Skip to content

Commit

Permalink
test(waitFor): Add current behavior for legacy fake timers and reques…
Browse files Browse the repository at this point in the history
…tAnimationFrame (#978)
  • Loading branch information
eps1lon authored Jun 20, 2021
1 parent fa3b91c commit f78d289
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/__tests__/fake-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,43 @@ test('recursive timers do not cause issues', async () => {

recurse = false
})

// TODO: Should fail i.e. work the same as with "modern fake timers" once https://github.com/facebook/jest/pull/11567 is released.
test('legacy fake timers do not waitFor requestAnimationFrame', async () => {
jest.useFakeTimers('legacy')

let exited = false
requestAnimationFrame(() => {
exited = true
})

await expect(async () => {
await waitFor(() => {
expect(exited).toBe(true)
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`
"expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
Ignored nodes: comments, <script />, <style />
<html>
<head />
<body />
</html>"
`)
})

test('modern fake timers do waitFor requestAnimationFrame', async () => {
jest.useFakeTimers('modern')

let exited = false
requestAnimationFrame(() => {
exited = true
})

await waitFor(() => {
expect(exited).toBe(true)
})
})

0 comments on commit f78d289

Please sign in to comment.