-
Notifications
You must be signed in to change notification settings - Fork 233
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
Tests timeout with jest fakeTimers and waitFor for on Promise.resolve calls #873
Comments
Probably another instance of #589. @mpeyper does For comparison, @5c077yP Could you check if the test still times out when you use import {render, waitForm} from '@testing-library/react'; // IMPORTANT: Use 12.x if using React 17
const fn = jest.fn();
function Component() {
useStateAndAsyncEffect(fn);
return null;
}
render(<Component />)
await waitFor(() => expect(fn).toHaveBeenCalled()); ? |
Hey @eps1lon , yes the test does work with |
No, we have never supported fake times. An attempt was made in a alpha build some time ago, but was shelved after the decision was made to move |
Yeah makes sense. I had some ideas for a simpler |
Came here to report the same thing. I fixed my issue by using the |
Hey, I get some of my tests timing out when using waitFor and jest.useFakeTimers, but not using a timer internally, but only
Promise.resolve
. As a context I'm trying to migrate a bigger code base from v4 to the latest version from v5 on some tests are failing. I'm also using jests faketimers by default for the tests.This might be a bit related to #631
react-hooks-testing-library
version: 8.0.1react
version: 17.02react-dom
version (if applicable): 17.02react-test-renderer
version (if applicable): 17.02node
version: 16.14.2yarn
version: 1.22.10Relevant code or config:
What happened:
The test fails from v5 and onwards, but worked in v4.
Suggested solution:
I was digging a bit into the code and saw v4 is calling
act
inside async-utils inside thewhile(true)
loop, while from v5 upwardsact
is only called once. I've tried to figure out the details, but not really sure why calling act more than once is making this work. I'm thinking about react flushing micro tasks more often, but also not very familiar with react internals/fibers.I've played with patch-package on got this diff working for me. Please let me know what you think about it 🙏
The text was updated successfully, but these errors were encountered: