Version 2.x not compatible with jest.useFakeTimers('modern');
See original GitHub issueDescribe the bug
Using jest.useFakeTimers('modern');
in any spec file, causes the tests to fail due to timeout error:
Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.
Downgrading to 1.14 fixes this, therefore I believe this is related to 2.x.
I am using jest.useFakeTimers('modern');
in order to call jest.setSystemTime
in my test just FYI.
Expected behavior
Tests should pass
Steps to Reproduce
Simple component:
import React from 'react';
import { Text } from 'react-native';
const TestComponent = () => (
<Text>hello world!</Text>
);
export default TestComponent;
spec file:
import React from 'react';
import { render } from 'react-native-testing-library';
import TestComponent from 'src/components/TestComponent';
jest.useFakeTimers('modern');
describe('TestComponent', () => {
it('should render hello world!', () => {
const utils = render(<TestComponent />);
expect(utils.getByText('hello world!')).not.toBeNull();
});
});
Versions
react: 16.13.1 => 16.13.1
react-native: 0.62.2 => 0.62.2
react-native-testing-library: ^2.1.0 => 2.1.0
react-test-renderer: ^16.13.0 => 16.13.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Jest 28: Shedding weight and improving compatibility
Jest shipped minimal support of exports in 27.3. However, it only supported the "main" entry point ( . ), and only if no...
Read more >Timer Mocks - Jest
useFakeTimers () . This is replacing the original implementation of setTimeout() and other timer functions. Timers can be restored to their ...
Read more >Jest 26: Tick Tock
In Jest 26, this new implementation will remain opt-in and can be activated by calling jest.useFakeTimers('modern') or by passing modern to the ...
Read more >Jest 27: New Defaults for Jest, 2021 edition
In the Jest 26 blog post about a year ago, we announced that after two major releases with few breaking changes, Jest 27...
Read more >The Jest Object
This is documentation for Jest 28.x, which is no longer actively maintained. For up-to-date documentation, see the latest version (29.3).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@thymikee I have created #506 that includes a test case. Please let me know if I can provide any additional information that would be helpful. Thanks!
Creating a new issue and a repro would be appreciated!