Skip to content

Commit

Permalink
[core] Fix more warnings with enzyme@3 and react@16 (#8641)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 10, 2017
1 parent 12dd6c7 commit 8d11064
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/test-utils/until.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function shallowRecursively(wrapper, selector, { context, ...other }) {
// enzyme@3
// const instance = wrapper.root().instance();
const instance = wrapper.root.instance();
if (instance.getChildContext) {
// The instance can be null with a stateless functional component and react >= 16.
if (instance && instance.getChildContext) {
newContext = {
...context,
...instance.getChildContext(),
Expand Down
16 changes: 13 additions & 3 deletions src/test-utils/until.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,26 @@ describe('until', () => {
assert.strictEqual(wrapper.contains(<div />), true);
});

const Foo = () => <Div />;
Foo.contextTypes = { quux: PropTypes.bool.isRequired };
// eslint-disable-next-line react/prefer-stateless-function
class Foo extends React.Component<{}> {
render() {
return <Div />;
}
}

Foo.contextTypes = {
quux: PropTypes.bool.isRequired,
};

it('context propagation passes down context from the root component', () => {
const EnhancedFoo = hoc(Foo);
const wrapper = until.call(shallow(<EnhancedFoo />), 'Foo', { context: { quux: true } });
const options = { context: { quux: true } };
const wrapper = until.call(shallow(<EnhancedFoo />, options), 'Foo', options);
assert.strictEqual(wrapper.context('quux'), true);
assert.strictEqual(wrapper.contains(<Div />), true);
});

// eslint-disable-next-line react/no-multi-comp
class Bar extends React.Component<{}> {
static childContextTypes = { quux: PropTypes.bool };
getChildContext = () => ({ quux: true });
Expand Down

0 comments on commit 8d11064

Please sign in to comment.