@@ -337,44 +337,60 @@ describe('ReactHooksInspectionIntegration', () => {
337337 ] ) ;
338338 } ) ;
339339
340- it ( 'should inject legacy context which is not a hook' , ( ) => {
341- class LegacyContextProvider extends React . Component < any > {
340+ it ( 'should be able to access functional legacy context during hook inspection' , ( ) => {
341+ let contextValue ;
342+
343+ class FirstLegacyContextProvider extends React . Component < any > {
342344 static childContextTypes = {
343345 string : PropTypes . string ,
344346 } ;
345-
346347 getChildContext ( ) {
347348 return {
348- string : 'abc ' ,
349+ string : 'valid context ' ,
349350 } ;
350351 }
352+ render ( ) {
353+ return this . props . children ;
354+ }
355+ }
351356
357+ class SecondLegacyContextProvider extends React . Component < any > {
358+ static childContextTypes = {
359+ string : PropTypes . string ,
360+ } ;
361+ getChildContext ( ) {
362+ return {
363+ string : 'invalid context' ,
364+ } ;
365+ }
352366 render ( ) {
353367 return this . props . children ;
354368 }
355369 }
356370
357371 function FunctionalLegacyContextConsumer ( props , context ) {
372+ contextValue = context . string ;
358373 return < div > { context . string } </ div > ;
359374 }
360375 FunctionalLegacyContextConsumer . contextTypes = {
361376 string : PropTypes . string ,
362377 } ;
378+
363379 const renderer = ReactTestRenderer . create (
364- < LegacyContextProvider >
365- < FunctionalLegacyContextConsumer />
366- </ LegacyContextProvider > ,
380+ < SecondLegacyContextProvider >
381+ < FirstLegacyContextProvider >
382+ < div >
383+ < FunctionalLegacyContextConsumer />
384+ </ div >
385+ </ FirstLegacyContextProvider >
386+ </ SecondLegacyContextProvider > ,
367387 ) ;
368388
369389 const childFiber = renderer . root
370390 . findByType ( FunctionalLegacyContextConsumer )
371391 . _currentFiber ( ) ;
372- const hasLegacyContext = ! ! childFiber . elementType . contextTypes ;
373- if ( hasLegacyContext ) {
374- expect ( ( ) =>
375- ReactDebugTools . inspectHooksOfFiber ( childFiber ) ,
376- ) . not . toThrow ( ) ;
377- }
392+ expect ( ( ) => ReactDebugTools . inspectHooksOfFiber ( childFiber ) ) . not . toThrow ( ) ;
393+ expect ( contextValue ) . toBe ( 'valid context' ) ;
378394 } ) ;
379395
380396 it ( 'should inspect custom hooks' , ( ) => {
0 commit comments