1111'use strict' ;
1212
1313let React ;
14+ let PropTypes ;
1415let ReactTestRenderer ;
1516let Scheduler ;
1617let ReactDebugTools ;
@@ -20,6 +21,7 @@ describe('ReactHooksInspectionIntegration', () => {
2021 beforeEach ( ( ) => {
2122 jest . resetModules ( ) ;
2223 React = require ( 'react' ) ;
24+ PropTypes = require ( 'prop-types' ) ;
2325 ReactTestRenderer = require ( 'react-test-renderer' ) ;
2426 Scheduler = require ( 'scheduler' ) ;
2527 act = ReactTestRenderer . act ;
@@ -335,6 +337,42 @@ describe('ReactHooksInspectionIntegration', () => {
335337 ] ) ;
336338 } ) ;
337339
340+ it ( 'should inject legacy context which is not a hook' , ( ) => {
341+ class LegacyContextProvider extends React . Component < any > {
342+ static childContextTypes = {
343+ string : PropTypes . string ,
344+ } ;
345+
346+ getChildContext ( ) {
347+ return {
348+ string : 'abc' ,
349+ } ;
350+ }
351+
352+ render ( ) {
353+ return this . props . children ;
354+ }
355+ }
356+
357+ function FunctionalLegacyContextConsumer ( props , context ) {
358+ return < div > { context . string} < / d i v > ;
359+ }
360+ FunctionalLegacyContextConsumer . contextTypes = {
361+ string : PropTypes . string ,
362+ } ;
363+ const renderer = ReactTestRenderer . create (
364+ < LegacyContextProvider >
365+ < FunctionalLegacyContextConsumer />
366+ </ LegacyContextProvider >
367+ ) ;
368+
369+ const childFiber = renderer . root . findByType ( FunctionalLegacyContextConsumer ) . _currentFiber ( ) ;
370+ const hasLegacyContext = ! ! childFiber . elementType . contextTypes ;
371+ if ( hasLegacyContext ) {
372+ expect ( ( ) => ReactDebugTools . inspectHooksOfFiber ( childFiber ) ) . not . toThrow ( ) ;
373+ }
374+ } ) ;
375+
338376 it ( 'should inspect custom hooks' , ( ) => {
339377 function useCustom ( ) {
340378 const [ value ] = React . useState ( 'hello' ) ;
0 commit comments