Skip to content

Commit f78d289

Browse files
authored
test(waitFor): Add current behavior for legacy fake timers and requestAnimationFrame (#978)
1 parent fa3b91c commit f78d289

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/__tests__/fake-timers.js

+40
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,43 @@ test('recursive timers do not cause issues', async () => {
7979

8080
recurse = false
8181
})
82+
83+
// TODO: Should fail i.e. work the same as with "modern fake timers" once https://github.com/facebook/jest/pull/11567 is released.
84+
test('legacy fake timers do not waitFor requestAnimationFrame', async () => {
85+
jest.useFakeTimers('legacy')
86+
87+
let exited = false
88+
requestAnimationFrame(() => {
89+
exited = true
90+
})
91+
92+
await expect(async () => {
93+
await waitFor(() => {
94+
expect(exited).toBe(true)
95+
})
96+
}).rejects.toThrowErrorMatchingInlineSnapshot(`
97+
"expect(received).toBe(expected) // Object.is equality
98+
99+
Expected: true
100+
Received: false
101+
102+
Ignored nodes: comments, <script />, <style />
103+
<html>
104+
<head />
105+
<body />
106+
</html>"
107+
`)
108+
})
109+
110+
test('modern fake timers do waitFor requestAnimationFrame', async () => {
111+
jest.useFakeTimers('modern')
112+
113+
let exited = false
114+
requestAnimationFrame(() => {
115+
exited = true
116+
})
117+
118+
await waitFor(() => {
119+
expect(exited).toBe(true)
120+
})
121+
})

0 commit comments

Comments
 (0)