Skip to content

Commit c9f9ebb

Browse files
committed
Add test for microtask queue during unmount
1 parent 91f0c75 commit c9f9ebb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/__tests__/cleanup.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ test('cleanup does not error when an element is not a child', async () => {
2626
render(<div />, {container: document.createElement('div')})
2727
await cleanup()
2828
})
29+
30+
test('cleanup waits for queued microtasks during unmount sequence', async () => {
31+
const spy = jest.fn()
32+
33+
const Test = () => {
34+
React.useEffect(() => () => setImmediate(spy))
35+
36+
return null
37+
}
38+
39+
render(<Test />)
40+
await cleanup()
41+
expect(spy).toHaveBeenCalledTimes(1)
42+
})

src/pure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ function render(
9090
}
9191

9292
async function cleanup() {
93-
await flush()
9493
mountedContainers.forEach(cleanupAtContainer)
94+
await flush()
9595
}
9696

9797
// maybe one day we'll expose this (perhaps even as a utility returned by render).

0 commit comments

Comments
 (0)