Error: Exceeded timeout of 5000 ms for a hook
Describe the bug
Tests fails with an error: thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.”
I tried to increase the timeout to one minute, but it didn't help. I also tried turning fakeTimers on and off, but this also had no effect. Works fine when using with renderer.create(<Button {...props} />) from react-test-renderer package.
Test example:
import 'react-native';
import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import { Button } from '../Button';
describe('<Button />', () => {
const props = {
title: 'Test',
onPress: jest.fn(),
};
it('should display a button', () => {
const { getByTestId, getByText, queryByTestId, toJSON } = render(<Button {...props} />);
});
});
Expected behavior
The test should pass without timeout error
Versions
@testing-library/react-native: ^9.1.0 => 10.0.0
react: 17.0.2 => 17.0.2
react-native: 0.68.2 => 0.68.2
react-test-renderer: ^17.0.2 => 17.0.2
Jest Config
{
"configs": [
{
"automock": false,
"cache": true,
"cacheDirectory": "/private/var/folders/hk/yj6yrf8s5wz__zwq5d55bqv00000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"cwd": "/Users/user/Documents/Projects/App",
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"extensionsToTreatAsEsm": [],
"fakeTimers": {
"enableGlobally": true
},
"forceCoverageMatch": [],
"globals": {
"ts-jest": {
"diagnostics": {
"exclude": [
"**"
]
}
}
},
"haste": {
"defaultPlatform": "ios",
"platforms": [
"android",
"ios",
"native"
]
},
"id": "d4fded5383daa5cad95de31c33ba7c39",
"injectGlobals": true,
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"moduleNameMapper": [
[
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$",
"identity-obj-proxy"
],
[
"^@/(.*)$",
"/Users/user/Documents/Projects/App/src/$1"
]
],
"modulePathIgnorePatterns": [],
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"restoreMocks": false,
"rootDir": "/Users/user/Documents/Projects/App",
"roots": [
"/Users/user/Documents/Projects/App"
],
"runner": "/Users/user/Documents/Projects/App/node_modules/jest-runner/build/index.js",
"sandboxInjectedGlobals": [
"Math"
],
"setupFiles": [
"/Users/user/Documents/Projects/App/node_modules/react-native/jest/setup.js",
"/Users/user/Documents/Projects/App/jest.setup.js"
],
"setupFilesAfterEnv": [
"/Users/user/Documents/Projects/App/node_modules/@testing-library/jest-native/extend-expect.js",
"/Users/user/Documents/Projects/App/jest.setup.js",
"/Users/user/Documents/Projects/App/jest.env.js"
],
"skipFilter": false,
"slowTestThreshold": 5,
"snapshotSerializers": [],
"testEnvironment": "/Users/user/Documents/Projects/App/node_modules/jest-environment-jsdom/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": [],
"testRunner": "/Users/user/Documents/Projects/App/node_modules/jest-circus/runner.js",
"transform": [
[
"^.+\\.tsx?$",
"/Users/user/Documents/Projects/App/node_modules/ts-jest/dist/index.js",
{}
],
[
"^.+\\.svg$",
"/Users/user/Documents/Projects/App/svgTransform.js",
{}
],
[
"^.+\\.(js|ts|tsx)$",
"/Users/user/Documents/Projects/App/node_modules/babel-jest/build/index.js",
{}
],
[
"^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$",
"/Users/user/Documents/Projects/App/node_modules/react-native/jest/assetFileTransformer.js",
{}
]
],
"transformIgnorePatterns": [
"/node_modules/(?!@react-native|react-native)"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"ci": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "/Users/user/Documents/Projects/App/coverage",
"coverageProvider": "babel",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"findRelatedTests": false,
"forceExit": false,
"json": false,
"lastCommit": false,
"listTests": false,
"logHeapUsage": false,
"maxConcurrency": 5,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "failure-change",
"onlyChanged": false,
"onlyFailures": false,
"passWithNoTests": false,
"projects": [],
"rootDir": "/Users/user/Documents/Projects/App",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testSequencer": "/Users/user/Documents/Projects/App/node_modules/@jest/test-sequencer/build/index.js",
"updateSnapshot": "new",
"useStderr": false,
"watch": false,
"watchAll": false,
"watchman": true
},
"version": "28.1.1"
}
@mdjastrzebski Tried to use jest 27 but still the same
@arthedza could you post a (minimal) repro repository for the issue?
@mdjastrzebski Unfortunately, I can't. I've recently updated react-native in the project and I found that react-native-testing-library is working with the previous version of react-native we have. So it may be caused by RN upgrade
A config of the working version:
{
"configs": [
{
"automock": false,
"cache": true,
"cacheDirectory": "/private/var/folders/hk/yj6yrf8s5wz__zwq5d55bqv00000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"cwd": "/Users/user/Documents/Projects/App",
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"extraGlobals": [],
"forceCoverageMatch": [],
"globals": {},
"haste": {
"defaultPlatform": "ios",
"platforms": [
"android",
"ios",
"native"
]
},
"injectGlobals": true,
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"moduleNameMapper": [
[
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$",
"identity-obj-proxy"
]
],
"modulePathIgnorePatterns": [],
"name": "60509ddc04d2e4cd7a9ffdb9bb6b8878",
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
"restoreMocks": false,
"rootDir": "/Users/user/Documents/Projects/App",
"roots": [
"/Users/user/Documents/Projects/App"
],
"runner": "jest-runner",
"setupFiles": [
"/Users/user/Documents/Projects/App/node_modules/react-native/jest/setup.js",
"/Users/user/Documents/Projects/App/jest.setup.js"
],
"setupFilesAfterEnv": [
"/Users/user/Documents/Projects/App/node_modules/@testing-library/jest-native/extend-expect.js"
],
"skipFilter": false,
"slowTestThreshold": 5,
"snapshotSerializers": [],
"testEnvironment": "/Users/user/Documents/Projects/App/node_modules/jest-environment-jsdom/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": [],
"testRunner": "/Users/user/Documents/Projects/App/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "fake",
"transform": [
[
"^.+\\.(js|ts|tsx)$",
"/Users/user/Documents/Projects/App/node_modules/babel-jest/build/index.js",
{}
],
[
"^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$",
"/Users/user/Documents/Projects/App/node_modules/react-native/jest/assetFileTransformer.js",
{}
]
],
"transformIgnorePatterns": [
"/node_modules/(?!@react-native|react-native)"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": 0,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": [],
"coverageDirectory": "/Users/user/Documents/Projects/App/coverage",
"coverageProvider": "babel",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"findRelatedTests": false,
"forceExit": false,
"json": false,
"lastCommit": false,
"listTests": false,
"logHeapUsage": false,
"maxConcurrency": 5,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "failure-change",
"onlyChanged": false,
"onlyFailures": false,
"passWithNoTests": false,
"projects": [],
"rootDir": "/Users/user/Documents/Projects/App",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testSequencer": "/Users/user/Documents/Projects/App/node_modules/@jest/test-sequencer/build/index.js",
"updateSnapshot": "new",
"useStderr": false,
"watch": false,
"watchAll": false,
"watchman": true
},
"version": "26.6.3"
}
I'm getting the same issue for my afterAll hook.
@arthedza do you mean that updating RN actually solved that issue or cause the issued?
Closing as stale.
Oh great - close an issue simply because no one cares to fix it
jest.setTimeout SIMPLY DOES NOT WORK

and result:

Fix your jest it's BROKEN
Oh wait - JUST USE MOCHA
It works.
@cybafelo:
-
The issue has been closed as there was no repro repository, so we could not reproduce the error locally on our machines and the OP did not respond for feedback for more than a month. In such case there is nothing we can do about the issue.
-
Your code screenshot does not seem to contain any RNTL-specific code. Maybe you should report your issue to Jest in such case?
If it indeed relates to RNTL, then please file a new GH issue & provide a minimal repro repository based on ours examples/basic example app. We can only try to help our uses if we can reproduce the problems they are facing.
- Finally, a kind reminder that we offer RNTL for free as our contribution to the wide RN community. We try to built the best tool we can, we value our users and try to help them solve the issues with RNTL the best we can BUT you are NOT entitled in any way for our support if you continue to rude. Please go somewhere else with your attitude.
Yes exactly, try to confuse everyone with your acronyms.
Your tool sucks, I would not use it if it werent made to believe popar by all sheep and asked over and over to use it
I take my rudeness somewhere else
On Tue, 8 Nov 2022, 17:08 Maciej Jastrzebski, @.***> wrote:
@cybafelo https://github.com/cybafelo:
The issue has been closed as there was no repro repository, so we could not reproduce the error locally on our machines and the OP did not respond for feedback for more than a month. In such case there is nothing we can do about the issue. 2.
Your code screenshot does not seem to contain any RNTL-specific code. Maybe you should report your issue to Jest in such case?
If it indeed relates to RNTL, then please file a new GH issue & provide a minimal repro repository based on ours examples/basic example app. We can only try to help our uses if we can reproduce the problems they are facing.
- Finally, a kind reminder that we offer RNTL for free as our contribution to the wide RN community. We try to built the best tool we ca, we value our users and try to help them solve the issues with RNTL the best we can BUT you are NOT entitled in any way for our support if you continue to rude. Please go somewhere else with your attitude.
— Reply to this email directly, view it on GitHub https://github.com/callstack/react-native-testing-library/issues/995#issuecomment-1307460119, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJBUOCDAYIHHXBS3ZKCZ43WHJ3IZANCNFSM5ZWUI2ZQ . You are receiving this because you were mentioned.Message ID: @.***>