Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: useFakerTimers and fetch/XHR do not seem to work #13018

Closed
phil-tutti opened this issue Jul 13, 2022 · 9 comments
Closed

[Bug]: useFakerTimers and fetch/XHR do not seem to work #13018

phil-tutti opened this issue Jul 13, 2022 · 9 comments

Comments

@phil-tutti
Copy link

Version

28.1.2

Steps to reproduce

  1. Clone https://github.com/phil-tutti/react-testing-library
  2. Run yarn install
  3. Run yarn test
  4. See the tests fail

Expected behavior

I expected to see all the tests pass.

Actual behavior

Tests that use useFakeTimers fail

Additional context

I tried a while to come up with a minimal reproduction case. However, to rule out any libraries like node-fetch, whatwg-fetch and so on, I also created a failing example with XMLHttpRequest.
Additionally, I tried to see if setTimeout works with useFakeTimers within a React component, and it seems to work.

Basically, what I observed, is that as soon as I start using useFakeTimers, requests (fetch/XHR) are not being sent, as if something is blocking them. Even running jest.runAllTimers() did not do the trick. Now I'm wondering if this is the expected behaviour, and if yes, maybe someone can shed some light here for me, as I'm really trying to understand that behaviour. When I digged a bit into node-fetch or whatwg-fetch, I saw that they worked with setTimeout and Promise, so in my eyes, whenever I run advanceTimersByTime, runAllTimer or runOnlyPendingTimers, it should run those requests, but it doesn't.

Environment

System:
    OS: macOS 12.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 16.15.1 - /usr/local/bin/node
    Yarn: 1.22.18 - ~/.yarn/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
  npmPackages:
    jest: 28.1.2 => 28.1.2
@mrazauskas
Copy link
Contributor

Did you try playing with useFakeTimers options? Depending on situation something like advanceTimers: true, or doNotFake: ['nextTick'] could make all work.

@phil-tutti
Copy link
Author

Hey @mrazauskas , thank you for your suggestions. I tried them out and played with the values a bit, but they don't seem to do the trick

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 12, 2022
@phil-tutti
Copy link
Author

Bumping it in order to not be auto-closed

@github-actions github-actions bot removed the Stale label Aug 15, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Sep 14, 2022
@phil-tutti
Copy link
Author

This is still an issue

@github-actions github-actions bot removed the Stale label Sep 14, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Oct 14, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants