Skip to content

Commit

Permalink
Merge branch 'master' into react-suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan committed Jan 17, 2019
2 parents 1bbe447 + c7282eb commit 1652d74
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/api/ShallowWrapper/instance.md
Expand Up @@ -30,7 +30,7 @@ class Stateful extends React.Component {
```
#### React 16.x
```jsx
test('shallow wrapper instance should not be null', () => {
test('shallow wrapper instance should be null', () => {
const wrapper = shallow(<Stateless />);
const instance = wrapper.instance();

Expand Down
13 changes: 5 additions & 8 deletions package.json
Expand Up @@ -60,8 +60,6 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"devDependencies": {
"acorn": "^6.0.4",
"acorn-jsx": "^5.0.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^7.2.3",
Expand All @@ -71,20 +69,19 @@
"babel-register": "^6.26.0",
"chai": "^4.2.0",
"coveralls": "^2.13.3",
"eslint": "^5.9.0",
"eslint": "^5.12.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-markdown": "^1.0.0-rc.0",
"eslint-plugin-react": "^7.11.1",
"espree": "^4.1.0",
"eslint-plugin-markdown": "^1.0.0",
"eslint-plugin-react": "^7.12.2",
"gitbook-cli": "^1.0.1",
"gitbook-plugin-anchors": "^0.7.1",
"gitbook-plugin-codeblock-disable-glossary": "0.0.1",
"gitbook-plugin-collapsible-menu": "^1.0.3",
"gitbook-plugin-edit-link": "^2.0.2",
"gitbook-plugin-github": "^2.0.0",
"glob-gitignore": "^1.0.9",
"glob-gitignore": "^1.0.11",
"in-publish": "^2.0.0",
"istanbul": "^1.0.0-alpha.2",
"istanbul-api": "^1.3.7",
Expand All @@ -98,7 +95,7 @@
"lerna": "^2.11.0",
"mocha": "^3.5.3",
"prop-types": "^15.6.2",
"rimraf": "^2.6.2",
"rimraf": "^2.6.3",
"safe-publish-latest": "^1.1.2",
"webpack": "^1.15.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-13/package.json
Expand Up @@ -52,7 +52,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-14/package.json
Expand Up @@ -55,7 +55,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-15.4/package.json
Expand Up @@ -56,7 +56,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-15/package.json
Expand Up @@ -55,7 +55,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-16.1/package.json
Expand Up @@ -55,7 +55,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
Expand Up @@ -29,6 +29,7 @@ import {
ensureKeyOrUndefined,
simulateError,
wrap,
getMaskedContext,
} from 'enzyme-adapter-utils';
import { findCurrentFiberUsingSlowPath } from 'react-reconciler/reflection';

Expand Down Expand Up @@ -315,7 +316,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
render(el, context) {
render(el, unmaskedContext) {
cachedNode = el;
/* eslint consistent-return: 0 */
if (typeof el.type === 'string') {
Expand All @@ -328,6 +329,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
Component.prototype.isReactComponent
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
);
const context = getMaskedContext(Component.contextTypes, unmaskedContext);

if (!isStateful && typeof Component === 'function') {
const wrappedEl = Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-16.2/package.json
Expand Up @@ -56,7 +56,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
Expand Up @@ -30,6 +30,7 @@ import {
ensureKeyOrUndefined,
simulateError,
wrap,
getMaskedContext,
} from 'enzyme-adapter-utils';
import { findCurrentFiberUsingSlowPath } from 'react-reconciler/reflection';

Expand Down Expand Up @@ -317,7 +318,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
render(el, context) {
render(el, unmaskedContext) {
cachedNode = el;
/* eslint consistent-return: 0 */
if (typeof el.type === 'string') {
Expand All @@ -330,6 +331,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
Component.prototype.isReactComponent
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
);
const context = getMaskedContext(Component.contextTypes, unmaskedContext);

if (!isStateful && typeof Component === 'function') {
const wrappedEl = Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-16.3/package.json
Expand Up @@ -57,7 +57,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-16/package.json
Expand Up @@ -56,7 +56,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
4 changes: 3 additions & 1 deletion packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Expand Up @@ -41,6 +41,7 @@ import {
ensureKeyOrUndefined,
simulateError,
wrap,
getMaskedContext,
} from 'enzyme-adapter-utils';
import findCurrentFiberUsingSlowPath from './findCurrentFiberUsingSlowPath';
import detectFiberTags from './detectFiberTags';
Expand Down Expand Up @@ -358,7 +359,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
render(el, context) {
render(el, unmaskedContext) {
cachedNode = el;
/* eslint consistent-return: 0 */
if (typeof el.type === 'string') {
Expand All @@ -372,6 +373,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
);

const context = getMaskedContext(Component.contextTypes, unmaskedContext);
if (!isStateful && typeof Component === 'function') {
const wrappedEl = Object.assign(
(...args) => Component(...args), // eslint-disable-line new-cap
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-helper/package.json
Expand Up @@ -46,7 +46,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0 || ^16.3.0-0 || ^16.4.0-0",
"safe-publish-latest": "^1.1.2"
Expand Down
3 changes: 2 additions & 1 deletion packages/enzyme-adapter-utils/package.json
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"function.prototype.name": "^1.1.0",
"object.assign": "^4.1.0",
"object.fromentries": "^2.0.0",
"prop-types": "^15.6.2",
"semver": "^5.6.0"
},
Expand All @@ -50,7 +51,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.2"
Expand Down
7 changes: 7 additions & 0 deletions packages/enzyme-adapter-utils/src/Utils.js
@@ -1,4 +1,5 @@
import functionName from 'function.prototype.name';
import fromEntries from 'object.fromentries';
import createMountWrapper from './createMountWrapper';
import createRenderWrapper from './createRenderWrapper';
import wrap from './wrapWithSimpleWrapper';
Expand Down Expand Up @@ -282,4 +283,10 @@ export function simulateError(

export function fakeDynamicImport(moduleToImport) {
return Promise.resolve({ default: moduleToImport });

export function getMaskedContext(contextTypes, unmaskedContext) {
if (!contextTypes || !unmaskedContext) {
return {};
}
return fromEntries(Object.keys(contextTypes).map(key => [key, unmaskedContext[key]]));
}
2 changes: 1 addition & 1 deletion packages/enzyme-example-mocha/package.json
Expand Up @@ -25,7 +25,7 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"espree": "^4.1.0",
"in-publish": "^2.0.0",
"jsdom": "^11.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/package.json
Expand Up @@ -52,7 +52,7 @@
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react": "^7.12.3",
"react-is": "^16.7.0"
}
}
24 changes: 24 additions & 0 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Expand Up @@ -4536,6 +4536,30 @@ describe('shallow', () => {
expect(wrapper.context().name).to.equal(context.name);
expect(wrapper.context('name')).to.equal(context.name);
});

it('filters context to childContextTypes', () => {
class Bar extends React.Component {
render() {
return <div />;
}
}
Bar.contextTypes = {
name: PropTypes.string,
};
class Foo extends React.Component {
render() {
return (
<div>
<Bar />
</div>
);
}
}

const context = { name: 'foo', hello: 'world' };
const wrapper = shallow(<Foo />, { context });
expect(wrapper.find(Bar).dive().context()).to.eql({ name: 'foo' });
});
});

describeIf(is('> 0.13'), 'stateless function components', () => {
Expand Down
33 changes: 33 additions & 0 deletions packages/enzyme-test-suite/test/adapter-utils-spec.jsx
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import {
displayNameOfNode,
ensureKeyOrUndefined,
getMaskedContext,
} from 'enzyme-adapter-utils';

import './_helpers/setupAdapters';
Expand Down Expand Up @@ -82,4 +83,36 @@ describe('enzyme-adapter-utils', () => {
});
});
});

describe('getMaskedContext', () => {
const contextTypes = {
a() {},
c() {},
};
const unmaskedContext = {
a: 1,
b: 2,
c: 3,
};
const falsies = [undefined, null, false, '', NaN, 0];

it('returns an empty object with falsy `contextTypes`', () => {
falsies.forEach((falsy) => {
expect(getMaskedContext(falsy, unmaskedContext)).to.eql({});
});
});

it('returns an empty object with falsy `unmaskedContext`', () => {
falsies.forEach((falsy) => {
expect(getMaskedContext(contextTypes, falsy)).to.eql({});
});
});

it('filters `unmaskedContext` down to `contextTypes`', () => {
expect(getMaskedContext(contextTypes, unmaskedContext)).to.eql({
a: unmaskedContext.a,
c: unmaskedContext.c,
});
});
});
});

0 comments on commit 1652d74

Please sign in to comment.