Skip to content

Commit

Permalink
test(unmount): Add expected behavior for unmount() and cleanup functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 15, 2020
1 parent 240900c commit ba59d1f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/__tests__/render.js
@@ -1,6 +1,8 @@
import React from 'react'
import ReactDOM from 'react-dom'
import {render, screen} from '../'
import {cleanup} from '../pure'
import {act} from 'react-dom/test-utils'

test('renders div into document', () => {
const ref = React.createRef()
Expand Down Expand Up @@ -87,3 +89,17 @@ test('renders options.wrapper around node', () => {
</div>
`)
})

test('flushes useEffect cleanup functions sync on unmount()', () => {
const spy = jest.fn()
function Component() {
React.useEffect(() => spy, [])
return null
}
const {unmount} = render(<Component />)
expect(spy).toHaveBeenCalledTimes(0)

unmount()

expect(spy).toHaveBeenCalledTimes(1)
})

0 comments on commit ba59d1f

Please sign in to comment.