File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -72,13 +72,21 @@ describe('renderPrepass', () => {
7272 const Outer = jest . fn ( ( ) => {
7373 const [ state , setState ] = useState ( 'default' )
7474
75- const memoed = useMemo ( ( ) => state , [ state ] )
75+ const memoedA = useMemo ( ( ) => state , [ state ] )
76+ expect ( memoedA ) . toBe ( state )
77+
78+ // This is to test changing dependency arrays
79+ const memoedB = useMemo (
80+ ( ) => state ,
81+ state === 'default' ? null : [ state ]
82+ )
83+ expect ( memoedB ) . toBe ( state )
84+
7685 const ref = useRef ( 'initial' )
77- expect ( memoed ) . toBe ( state )
7886 expect ( ref . current ) . toBe ( 'initial' )
7987
8088 const value = getValue ( )
81- setState ( value )
89+ setState ( ( ) => value )
8290
8391 return < Inner value = { value } state = { state } />
8492 } )
Original file line number Diff line number Diff line change @@ -280,15 +280,20 @@ describe('visitElement', () => {
280280 it ( 'renders function components' , ( ) => {
281281 const Test = ( ) => {
282282 const [ value , setValue ] = useState ( 'a' )
283- if ( value === 'a' ) setValue ( 'b' )
283+ if ( value === 'a' ) {
284+ setValue ( 'b' )
285+ setValue ( 'c' )
286+ setValue ( 'd' )
287+ }
288+
284289 return < Noop > { value } </ Noop >
285290 }
286291
287292 const visitor = jest . fn ( )
288293 const children = visitElement ( < Test /> , [ ] , visitor )
289294 expect ( children . length ) . toBe ( 1 )
290295 expect ( children [ 0 ] . type ) . toBe ( Noop )
291- expect ( children [ 0 ] . props . children ) . toBe ( 'b ' )
296+ expect ( children [ 0 ] . props . children ) . toBe ( 'd ' )
292297 expect ( visitor ) . toHaveBeenCalledWith ( < Test /> )
293298 } )
294299
Original file line number Diff line number Diff line change 1+ import { setCurrentContextStore } from '../context'
12import { getCurrentIdentity , Dispatcher } from '../dispatcher'
23
34describe ( 'getCurrentIdentity' , ( ) => {
@@ -6,6 +7,16 @@ describe('getCurrentIdentity', () => {
67 } )
78} )
89
10+ describe ( 'readContext' , ( ) => {
11+ it ( 'calls readContextValue' , ( ) => {
12+ const map = new Map ( )
13+ const ctx = { }
14+ setCurrentContextStore ( map )
15+ map . set ( ctx , 'value' )
16+ expect ( Dispatcher . readContext ( ctx ) ) . toBe ( 'value' )
17+ } )
18+ } )
19+
920describe ( 'useEffect' , ( ) => {
1021 it ( 'is a noop' , ( ) => {
1122 expect ( Dispatcher . useEffect ) . not . toThrow ( )
You can’t perform that action at this time.
0 commit comments