question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version 2.x not compatible with jest.useFakeTimers('modern');

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dcalhouncommented, Aug 14, 2020

@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!

1reaction
thymikeecommented, Aug 10, 2020

Creating a new issue and a repro would be appreciated!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found