TheBrainFamily / wait-for-expect

Wait for expectation to be true, useful for integration and end to end testing. Integral part of react-testing-library.
MIT License
293 stars 31 forks source link

Changes legacy timers to modern timers in Jest v27 #34

Open voicis opened 2 years ago

voicis commented 2 years ago

It's impossible to use wait-for-expect and legacy fake timers with Jest v27.

If you set legacy timers in jest config https://jestjs.io/docs/configuration#timers-string, which enables legacy timers for all tests, however after you call waitForExpect it changes to modern timers and they will be used for the rest of the test.

I suspect that this is because the following code which now sets modern timers by default. https://github.com/TheBrainFamily/wait-for-expect/blob/6be6e2ed8e47fd5bc62ab2fc4bd39289c58f2f66/src/helpers.ts#L22

connorshea commented 2 years ago

My solution is somewhat specific but my problem appears to be a combination of this issue and one related to my usage of the msw library. https://github.com/mswjs/msw/issues/1163

I solved it by replacing waitForExpect with waitFor from @testing-library/vue (which needs to be the next version, the stable version doesn't support Vue 3 yet)