Skip to content

Commit ba59d1f

Browse files
committed
test(unmount): Add expected behavior for unmount() and cleanup functions
1 parent 240900c commit ba59d1f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/__tests__/render.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33
import {render, screen} from '../'
4+
import {cleanup} from '../pure'
5+
import {act} from 'react-dom/test-utils'
46

57
test('renders div into document', () => {
68
const ref = React.createRef()
@@ -87,3 +89,17 @@ test('renders options.wrapper around node', () => {
8789
</div>
8890
`)
8991
})
92+
93+
test('flushes useEffect cleanup functions sync on unmount()', () => {
94+
const spy = jest.fn()
95+
function Component() {
96+
React.useEffect(() => spy, [])
97+
return null
98+
}
99+
const {unmount} = render(<Component />)
100+
expect(spy).toHaveBeenCalledTimes(0)
101+
102+
unmount()
103+
104+
expect(spy).toHaveBeenCalledTimes(1)
105+
})

0 commit comments

Comments
 (0)