@@ -1571,4 +1571,90 @@ describe('InspectedElementContext', () => {
15711571
15721572 done ( ) ;
15731573 } ) ;
1574+
1575+ it ( 'display complex values of useDebugValue' , async done => {
1576+ let getInspectedElementPath : GetInspectedElementPath = ( ( null : any ) : GetInspectedElementPath ) ;
1577+ let inspectedElement = null ;
1578+ function Suspender ( { target} ) {
1579+ const context = React . useContext ( InspectedElementContext ) ;
1580+ getInspectedElementPath = context . getInspectedElementPath ;
1581+ inspectedElement = context . getInspectedElement ( target ) ;
1582+ return null ;
1583+ }
1584+
1585+ const container = document . createElement ( 'div' ) ;
1586+
1587+ function useNotDebuggableHook ( ) {
1588+ React . useDebugValue ( { foo : 2 } ) ;
1589+ React . useState ( 1 ) ;
1590+ return 1 ;
1591+ }
1592+ function IgnoredComplexValue ( ) {
1593+ useNotDebuggableHook ( ) ;
1594+ return null ;
1595+ }
1596+
1597+ function useDebuggableHook ( ) {
1598+ React . useDebugValue ( { foo : 2 } ) ;
1599+ return 1 ;
1600+ }
1601+ function DisplayedComplexValue ( ) {
1602+ useDebuggableHook ( ) ;
1603+ React . useState ( 1 ) ;
1604+ return null ;
1605+ }
1606+
1607+ await utils . actAsync ( ( ) =>
1608+ ReactDOM . render (
1609+ < React . Fragment >
1610+ < IgnoredComplexValue />
1611+ < DisplayedComplexValue />
1612+ </ React . Fragment > ,
1613+ container ,
1614+ ) ,
1615+ ) ;
1616+
1617+ const ignoredComplexValueIndex = 0
1618+ const ignoredComplexValueId = ( ( store . getElementIDAtIndex ( ignoredComplexValueIndex ) : any ) : number ) ;
1619+ await utils . actAsync (
1620+ ( ) =>
1621+ TestRenderer . create (
1622+ < Contexts
1623+ defaultSelectedElementID = { ignoredComplexValueId }
1624+ defaultSelectedElementIndex = { ignoredComplexValueIndex } >
1625+ < React . Suspense fallback = { null } >
1626+ < Suspender target = { ignoredComplexValueId } />
1627+ </ React . Suspense >
1628+ </ Contexts > ,
1629+ ) ,
1630+ false ,
1631+ ) ;
1632+ expect ( getInspectedElementPath ) . not . toBeNull ( ) ;
1633+ expect ( inspectedElement ) . not . toBeNull ( ) ;
1634+ expect ( inspectedElement ) . toMatchSnapshot ( 'IgnoredComplexValue' ) ;
1635+
1636+ inspectedElement = null ;
1637+
1638+
1639+ const displayedComplexValueIndex = 1
1640+ const displayedComplexValueId = ( ( store . getElementIDAtIndex ( displayedComplexValueIndex ) : any ) : number ) ;
1641+ await utils . actAsync (
1642+ ( ) =>
1643+ TestRenderer . create (
1644+ < Contexts
1645+ defaultSelectedElementID = { displayedComplexValueId }
1646+ defaultSelectedElementIndex = { displayedComplexValueIndex } >
1647+ < React . Suspense fallback = { null } >
1648+ < Suspender target = { displayedComplexValueId } />
1649+ </ React . Suspense >
1650+ </ Contexts > ,
1651+ ) ,
1652+ false ,
1653+ ) ;
1654+ expect ( getInspectedElementPath ) . not . toBeNull ( ) ;
1655+ expect ( inspectedElement ) . not . toBeNull ( ) ;
1656+ expect ( inspectedElement ) . toMatchSnapshot ( 'DisplayedComplexValue' ) ;
1657+
1658+ done ( ) ;
1659+ } ) ;
15741660} ) ;
0 commit comments