You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -192,3 +192,64 @@ test('when a promise is returned, if that is not resolved within the timeout, th
192
192
</html>"
193
193
`)
194
194
})
195
+
196
+
test('if you switch from fake timers to real timers during the wait period you get an error',async()=>{
197
+
jest.useFakeTimers()
198
+
constwaitForError=waitFor(()=>{
199
+
thrownewError('this error message does not matter...')
200
+
}).catch(e=>e)
201
+
202
+
// this is the problem...
203
+
jest.useRealTimers()
204
+
205
+
consterror=awaitwaitForError
206
+
207
+
expect(error.message).toMatchInlineSnapshot(
208
+
`"Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830"`,
209
+
)
210
+
// stack trace has this file in it
211
+
expect(error.stack).toMatch(__dirname)
212
+
})
213
+
214
+
test('if you switch from real timers to fake timers during the wait period you get an error',async()=>{
215
+
constwaitForError=waitFor(()=>{
216
+
thrownewError('this error message does not matter...')
217
+
}).catch(e=>e)
218
+
219
+
// this is the problem...
220
+
jest.useFakeTimers()
221
+
consterror=awaitwaitForError
222
+
223
+
expect(error.message).toMatchInlineSnapshot(
224
+
`"Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830"`,
225
+
)
226
+
// stack trace has this file in it
227
+
expect(error.stack).toMatch(__dirname)
228
+
})
229
+
230
+
test('the fake timers => real timers error shows the original stack trace when configured to do so',async()=>{
231
+
jest.useFakeTimers()
232
+
constwaitForError=waitFor(
233
+
()=>{
234
+
thrownewError('this error message does not matter...')
`Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,
`Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`,
0 commit comments