diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js index 01461dfc1648e..b4c572fa2778f 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js @@ -11,6 +11,7 @@ 'use strict'; let React; +let PropTypes; let ReactTestRenderer; let Scheduler; let ReactDebugTools; @@ -20,6 +21,7 @@ describe('ReactHooksInspectionIntegration', () => { beforeEach(() => { jest.resetModules(); React = require('react'); + PropTypes = require('prop-types'); ReactTestRenderer = require('react-test-renderer'); Scheduler = require('scheduler'); act = ReactTestRenderer.act; @@ -335,6 +337,46 @@ describe('ReactHooksInspectionIntegration', () => { ]); }); + it('should inject legacy context which is not a hook', () => { + class LegacyContextProvider extends React.Component { + static childContextTypes = { + string: PropTypes.string, + }; + + getChildContext() { + return { + string: 'abc', + }; + } + + render() { + return this.props.children; + } + } + + function FunctionalLegacyContextConsumer(props, context) { + return
{context.string}
; + } + FunctionalLegacyContextConsumer.contextTypes = { + string: PropTypes.string, + }; + const renderer = ReactTestRenderer.create( + + + , + ); + + const childFiber = renderer.root + .findByType(FunctionalLegacyContextConsumer) + ._currentFiber(); + const hasLegacyContext = !!childFiber.elementType.contextTypes; + if (hasLegacyContext) { + expect(() => + ReactDebugTools.inspectHooksOfFiber(childFiber), + ).not.toThrow(); + } + }); + it('should inspect custom hooks', () => { function useCustom() { const [value] = React.useState('hello');