Skip to content

Commit f59eee4

Browse files
committed
Add additional useReducer test
1 parent 5afeca3 commit f59eee4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/__tests__/visitor.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import React, {
22
Component,
33
Fragment,
44
createContext,
5+
useReducer,
56
useContext,
67
useState
78
} from 'react'
9+
810
import { createPortal } from 'react-dom'
911

1012
import {
@@ -256,6 +258,23 @@ describe('visitElement', () => {
256258
expect(visitor).toHaveBeenCalledWith(<Test />)
257259
})
258260

261+
it('renders function components with reducers', () => {
262+
const reducer = (prev, action) => (action === 'increment' ? prev + 1 : prev)
263+
264+
const Test = () => {
265+
const [value, dispatch] = useReducer(reducer, 0)
266+
if (value === 0) dispatch('increment')
267+
return <Noop>{value}</Noop>
268+
}
269+
270+
const visitor = jest.fn()
271+
const children = visitElement(<Test />, [], visitor)
272+
expect(children.length).toBe(1)
273+
expect(children[0].type).toBe(Noop)
274+
expect(children[0].props.children).toBe(1)
275+
expect(visitor).toHaveBeenCalledWith(<Test />)
276+
})
277+
259278
it('renders function components with context', () => {
260279
const Context = createContext('default')
261280
const Test = () => {

0 commit comments

Comments
 (0)