@@ -268,6 +268,183 @@ describe('ReactHooksInspectionIntegration', () => {
268268 ] ) ;
269269 } ) ;
270270
271+ // @gate experimental || www
272+ it ( 'should inspect the current state of all stateful hooks, including useInsertionEffect' , ( ) => {
273+ const useInsertionEffect = React . unstable_useInsertionEffect ;
274+ const outsideRef = React . createRef ( ) ;
275+ function effect ( ) { }
276+ function Foo ( props ) {
277+ const [ state1 , setState ] = React . useState ( 'a' ) ;
278+ const [ state2 , dispatch ] = React . useReducer ( ( s , a ) => a . value , 'b' ) ;
279+ const ref = React . useRef ( 'c' ) ;
280+
281+ useInsertionEffect ( effect ) ;
282+ React . useLayoutEffect ( effect ) ;
283+ React . useEffect ( effect ) ;
284+
285+ React . useImperativeHandle (
286+ outsideRef ,
287+ ( ) => {
288+ // Return a function so that jest treats them as non-equal.
289+ return function Instance ( ) { } ;
290+ } ,
291+ [ ] ,
292+ ) ;
293+
294+ React . useMemo ( ( ) => state1 + state2 , [ state1 ] ) ;
295+
296+ function update ( ) {
297+ act ( ( ) => {
298+ setState ( 'A' ) ;
299+ } ) ;
300+ act ( ( ) => {
301+ dispatch ( { value : 'B' } ) ;
302+ } ) ;
303+ ref . current = 'C' ;
304+ }
305+ const memoizedUpdate = React . useCallback ( update , [ ] ) ;
306+ return (
307+ < div onClick = { memoizedUpdate } >
308+ { state1 } { state2 }
309+ </ div >
310+ ) ;
311+ }
312+ let renderer ;
313+ act ( ( ) => {
314+ renderer = ReactTestRenderer . create ( < Foo prop = "prop" /> ) ;
315+ } ) ;
316+
317+ let childFiber = renderer . root . findByType ( Foo ) . _currentFiber ( ) ;
318+
319+ const { onClick : updateStates } = renderer . root . findByType ( 'div' ) . props ;
320+
321+ let tree = ReactDebugTools . inspectHooksOfFiber ( childFiber ) ;
322+ expect ( tree ) . toEqual ( [
323+ {
324+ isStateEditable : true ,
325+ id : 0 ,
326+ name : 'State' ,
327+ value : 'a' ,
328+ subHooks : [ ] ,
329+ } ,
330+ {
331+ isStateEditable : true ,
332+ id : 1 ,
333+ name : 'Reducer' ,
334+ value : 'b' ,
335+ subHooks : [ ] ,
336+ } ,
337+ { isStateEditable : false , id : 2 , name : 'Ref' , value : 'c' , subHooks : [ ] } ,
338+ {
339+ isStateEditable : false ,
340+ id : 3 ,
341+ name : 'InsertionEffect' ,
342+ value : effect ,
343+ subHooks : [ ] ,
344+ } ,
345+ {
346+ isStateEditable : false ,
347+ id : 4 ,
348+ name : 'LayoutEffect' ,
349+ value : effect ,
350+ subHooks : [ ] ,
351+ } ,
352+ {
353+ isStateEditable : false ,
354+ id : 5 ,
355+ name : 'Effect' ,
356+ value : effect ,
357+ subHooks : [ ] ,
358+ } ,
359+ {
360+ isStateEditable : false ,
361+ id : 6 ,
362+ name : 'ImperativeHandle' ,
363+ value : outsideRef . current ,
364+ subHooks : [ ] ,
365+ } ,
366+ {
367+ isStateEditable : false ,
368+ id : 7 ,
369+ name : 'Memo' ,
370+ value : 'ab' ,
371+ subHooks : [ ] ,
372+ } ,
373+ {
374+ isStateEditable : false ,
375+ id : 8 ,
376+ name : 'Callback' ,
377+ value : updateStates ,
378+ subHooks : [ ] ,
379+ } ,
380+ ] ) ;
381+
382+ updateStates ( ) ;
383+
384+ childFiber = renderer . root . findByType ( Foo ) . _currentFiber ( ) ;
385+ tree = ReactDebugTools . inspectHooksOfFiber ( childFiber ) ;
386+
387+ expect ( tree ) . toEqual ( [
388+ {
389+ isStateEditable : true ,
390+ id : 0 ,
391+ name : 'State' ,
392+ value : 'A' ,
393+ subHooks : [ ] ,
394+ } ,
395+ {
396+ isStateEditable : true ,
397+ id : 1 ,
398+ name : 'Reducer' ,
399+ value : 'B' ,
400+ subHooks : [ ] ,
401+ } ,
402+ { isStateEditable : false , id : 2 , name : 'Ref' , value : 'C' , subHooks : [ ] } ,
403+ {
404+ isStateEditable : false ,
405+ id : 3 ,
406+ name : 'InsertionEffect' ,
407+ value : effect ,
408+ subHooks : [ ] ,
409+ } ,
410+ {
411+ isStateEditable : false ,
412+ id : 4 ,
413+ name : 'LayoutEffect' ,
414+ value : effect ,
415+ subHooks : [ ] ,
416+ } ,
417+ {
418+ isStateEditable : false ,
419+ id : 5 ,
420+ name : 'Effect' ,
421+ value : effect ,
422+ subHooks : [ ] ,
423+ } ,
424+ {
425+ isStateEditable : false ,
426+ id : 6 ,
427+ name : 'ImperativeHandle' ,
428+ value : outsideRef . current ,
429+ subHooks : [ ] ,
430+ } ,
431+ {
432+ isStateEditable : false ,
433+ id : 7 ,
434+ name : 'Memo' ,
435+ value : 'Ab' ,
436+ subHooks : [ ] ,
437+ } ,
438+ {
439+ isStateEditable : false ,
440+ id : 8 ,
441+ name : 'Callback' ,
442+ value : updateStates ,
443+ subHooks : [ ] ,
444+ } ,
445+ ] ) ;
446+ } ) ;
447+
271448 it ( 'should inspect the value of the current provider in useContext' , ( ) => {
272449 const MyContext = React . createContext ( 'default' ) ;
273450 function Foo ( props ) {
0 commit comments