Skip to content

Commit 1689628

Browse files
committed
add test
1 parent 87339c3 commit 1689628

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
let React;
14+
let PropTypes;
1415
let ReactTestRenderer;
1516
let Scheduler;
1617
let 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}</div>;
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

Comments
 (0)