Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bl00mber committed Sep 4, 2020
1 parent 87339c3 commit bc8cddd
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'use strict';

let React;
let PropTypes;
let ReactTestRenderer;
let Scheduler;
let ReactDebugTools;
Expand All @@ -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;
Expand Down Expand Up @@ -335,6 +337,46 @@ describe('ReactHooksInspectionIntegration', () => {
]);
});

it('should inject legacy context which is not a hook', () => {
class LegacyContextProvider extends React.Component<any> {
static childContextTypes = {
string: PropTypes.string,
};

getChildContext() {
return {
string: 'abc',
};
}

render() {
return this.props.children;
}
}

function FunctionalLegacyContextConsumer(props, context) {
return <div>{context.string}</div>;
}
FunctionalLegacyContextConsumer.contextTypes = {
string: PropTypes.string,
};
const renderer = ReactTestRenderer.create(
<LegacyContextProvider>
<FunctionalLegacyContextConsumer />
</LegacyContextProvider>,
);

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');
Expand Down

0 comments on commit bc8cddd

Please sign in to comment.