File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ import React, {
22 Component ,
33 Fragment ,
44 createContext ,
5+ useReducer ,
56 useContext ,
67 useState
78} from 'react'
9+
810import { createPortal } from 'react-dom'
911
1012import {
@@ -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 = ( ) => {
You can’t perform that action at this time.
0 commit comments