Closed
Description
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"
}
Metadata
Metadata
Assignees
Labels
No labels