Skip to content

Commit 1652d74

Browse files
authored
Merge branch 'master' into react-suspense
2 parents 1bbe447 + c7282eb commit 1652d74

File tree

23 files changed

+168
-26
lines changed

23 files changed

+168
-26
lines changed

docs/api/ShallowWrapper/instance.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Stateful extends React.Component {
3030
```
3131
#### React 16.x
3232
```jsx
33-
test('shallow wrapper instance should not be null', () => {
33+
test('shallow wrapper instance should be null', () => {
3434
const wrapper = shallow(<Stateless />);
3535
const instance = wrapper.instance();
3636

package.json

+5-8
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
"author": "Leland Richardson <leland.richardson@airbnb.com>",
6161
"license": "MIT",
6262
"devDependencies": {
63-
"acorn": "^6.0.4",
64-
"acorn-jsx": "^5.0.1",
6563
"babel-cli": "^6.26.0",
6664
"babel-core": "^6.26.3",
6765
"babel-eslint": "^7.2.3",
@@ -71,20 +69,19 @@
7169
"babel-register": "^6.26.0",
7270
"chai": "^4.2.0",
7371
"coveralls": "^2.13.3",
74-
"eslint": "^5.9.0",
72+
"eslint": "^5.12.0",
7573
"eslint-config-airbnb": "^17.1.0",
7674
"eslint-plugin-import": "^2.14.0",
7775
"eslint-plugin-jsx-a11y": "^6.1.2",
78-
"eslint-plugin-markdown": "^1.0.0-rc.0",
79-
"eslint-plugin-react": "^7.11.1",
80-
"espree": "^4.1.0",
76+
"eslint-plugin-markdown": "^1.0.0",
77+
"eslint-plugin-react": "^7.12.2",
8178
"gitbook-cli": "^1.0.1",
8279
"gitbook-plugin-anchors": "^0.7.1",
8380
"gitbook-plugin-codeblock-disable-glossary": "0.0.1",
8481
"gitbook-plugin-collapsible-menu": "^1.0.3",
8582
"gitbook-plugin-edit-link": "^2.0.2",
8683
"gitbook-plugin-github": "^2.0.0",
87-
"glob-gitignore": "^1.0.9",
84+
"glob-gitignore": "^1.0.11",
8885
"in-publish": "^2.0.0",
8986
"istanbul": "^1.0.0-alpha.2",
9087
"istanbul-api": "^1.3.7",
@@ -98,7 +95,7 @@
9895
"lerna": "^2.11.0",
9996
"mocha": "^3.5.3",
10097
"prop-types": "^15.6.2",
101-
"rimraf": "^2.6.2",
98+
"rimraf": "^2.6.3",
10299
"safe-publish-latest": "^1.1.2",
103100
"webpack": "^1.15.0"
104101
},

packages/enzyme-adapter-react-13/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint-config-airbnb": "^17.1.0",
5353
"eslint-plugin-import": "^2.14.0",
5454
"eslint-plugin-jsx-a11y": "^6.1.2",
55-
"eslint-plugin-react": "^7.11.1",
55+
"eslint-plugin-react": "^7.12.3",
5656
"in-publish": "^2.0.0",
5757
"rimraf": "^2.6.2",
5858
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-14/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"eslint-config-airbnb": "^17.1.0",
5656
"eslint-plugin-import": "^2.14.0",
5757
"eslint-plugin-jsx-a11y": "^6.1.2",
58-
"eslint-plugin-react": "^7.11.1",
58+
"eslint-plugin-react": "^7.12.3",
5959
"in-publish": "^2.0.0",
6060
"rimraf": "^2.6.2",
6161
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-15.4/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"eslint-config-airbnb": "^17.1.0",
5757
"eslint-plugin-import": "^2.14.0",
5858
"eslint-plugin-jsx-a11y": "^6.1.2",
59-
"eslint-plugin-react": "^7.11.1",
59+
"eslint-plugin-react": "^7.12.3",
6060
"in-publish": "^2.0.0",
6161
"rimraf": "^2.6.2",
6262
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-15/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"eslint-config-airbnb": "^17.1.0",
5656
"eslint-plugin-import": "^2.14.0",
5757
"eslint-plugin-jsx-a11y": "^6.1.2",
58-
"eslint-plugin-react": "^7.11.1",
58+
"eslint-plugin-react": "^7.12.3",
5959
"in-publish": "^2.0.0",
6060
"rimraf": "^2.6.2",
6161
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-16.1/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"eslint-config-airbnb": "^17.1.0",
5656
"eslint-plugin-import": "^2.14.0",
5757
"eslint-plugin-jsx-a11y": "^6.1.2",
58-
"eslint-plugin-react": "^7.11.1",
58+
"eslint-plugin-react": "^7.12.3",
5959
"in-publish": "^2.0.0",
6060
"rimraf": "^2.6.2",
6161
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-16.1/src/ReactSixteenOneAdapter.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
ensureKeyOrUndefined,
3030
simulateError,
3131
wrap,
32+
getMaskedContext,
3233
} from 'enzyme-adapter-utils';
3334
import { findCurrentFiberUsingSlowPath } from 'react-reconciler/reflection';
3435

@@ -315,7 +316,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
315316
let isDOM = false;
316317
let cachedNode = null;
317318
return {
318-
render(el, context) {
319+
render(el, unmaskedContext) {
319320
cachedNode = el;
320321
/* eslint consistent-return: 0 */
321322
if (typeof el.type === 'string') {
@@ -328,6 +329,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
328329
Component.prototype.isReactComponent
329330
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
330331
);
332+
const context = getMaskedContext(Component.contextTypes, unmaskedContext);
331333

332334
if (!isStateful && typeof Component === 'function') {
333335
const wrappedEl = Object.assign(

packages/enzyme-adapter-react-16.2/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"eslint-config-airbnb": "^17.1.0",
5757
"eslint-plugin-import": "^2.14.0",
5858
"eslint-plugin-jsx-a11y": "^6.1.2",
59-
"eslint-plugin-react": "^7.11.1",
59+
"eslint-plugin-react": "^7.12.3",
6060
"in-publish": "^2.0.0",
6161
"rimraf": "^2.6.2",
6262
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-16.2/src/ReactSixteenTwoAdapter.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
ensureKeyOrUndefined,
3131
simulateError,
3232
wrap,
33+
getMaskedContext,
3334
} from 'enzyme-adapter-utils';
3435
import { findCurrentFiberUsingSlowPath } from 'react-reconciler/reflection';
3536

@@ -317,7 +318,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
317318
let isDOM = false;
318319
let cachedNode = null;
319320
return {
320-
render(el, context) {
321+
render(el, unmaskedContext) {
321322
cachedNode = el;
322323
/* eslint consistent-return: 0 */
323324
if (typeof el.type === 'string') {
@@ -330,6 +331,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
330331
Component.prototype.isReactComponent
331332
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
332333
);
334+
const context = getMaskedContext(Component.contextTypes, unmaskedContext);
333335

334336
if (!isStateful && typeof Component === 'function') {
335337
const wrappedEl = Object.assign(

packages/enzyme-adapter-react-16.3/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"eslint-config-airbnb": "^17.1.0",
5858
"eslint-plugin-import": "^2.14.0",
5959
"eslint-plugin-jsx-a11y": "^6.1.2",
60-
"eslint-plugin-react": "^7.11.1",
60+
"eslint-plugin-react": "^7.12.3",
6161
"in-publish": "^2.0.0",
6262
"rimraf": "^2.6.2",
6363
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-16/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"eslint-config-airbnb": "^17.1.0",
5757
"eslint-plugin-import": "^2.14.0",
5858
"eslint-plugin-jsx-a11y": "^6.1.2",
59-
"eslint-plugin-react": "^7.11.1",
59+
"eslint-plugin-react": "^7.12.3",
6060
"in-publish": "^2.0.0",
6161
"rimraf": "^2.6.2",
6262
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
ensureKeyOrUndefined,
4242
simulateError,
4343
wrap,
44+
getMaskedContext,
4445
} from 'enzyme-adapter-utils';
4546
import findCurrentFiberUsingSlowPath from './findCurrentFiberUsingSlowPath';
4647
import detectFiberTags from './detectFiberTags';
@@ -358,7 +359,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
358359
let isDOM = false;
359360
let cachedNode = null;
360361
return {
361-
render(el, context) {
362+
render(el, unmaskedContext) {
362363
cachedNode = el;
363364
/* eslint consistent-return: 0 */
364365
if (typeof el.type === 'string') {
@@ -372,6 +373,7 @@ class ReactSixteenAdapter extends EnzymeAdapter {
372373
|| Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
373374
);
374375

376+
const context = getMaskedContext(Component.contextTypes, unmaskedContext);
375377
if (!isStateful && typeof Component === 'function') {
376378
const wrappedEl = Object.assign(
377379
(...args) => Component(...args), // eslint-disable-line new-cap

packages/enzyme-adapter-react-helper/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"eslint-config-airbnb": "^17.1.0",
4747
"eslint-plugin-import": "^2.14.0",
4848
"eslint-plugin-jsx-a11y": "^6.1.2",
49-
"eslint-plugin-react": "^7.11.1",
49+
"eslint-plugin-react": "^7.12.3",
5050
"in-publish": "^2.0.0",
5151
"react": "0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0 || ^16.3.0-0 || ^16.4.0-0",
5252
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-utils/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"dependencies": {
3737
"function.prototype.name": "^1.1.0",
3838
"object.assign": "^4.1.0",
39+
"object.fromentries": "^2.0.0",
3940
"prop-types": "^15.6.2",
4041
"semver": "^5.6.0"
4142
},
@@ -50,7 +51,7 @@
5051
"eslint-config-airbnb": "^17.1.0",
5152
"eslint-plugin-import": "^2.14.0",
5253
"eslint-plugin-jsx-a11y": "^6.1.2",
53-
"eslint-plugin-react": "^7.11.1",
54+
"eslint-plugin-react": "^7.12.3",
5455
"in-publish": "^2.0.0",
5556
"rimraf": "^2.6.2",
5657
"safe-publish-latest": "^1.1.2"

packages/enzyme-adapter-utils/src/Utils.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import functionName from 'function.prototype.name';
2+
import fromEntries from 'object.fromentries';
23
import createMountWrapper from './createMountWrapper';
34
import createRenderWrapper from './createRenderWrapper';
45
import wrap from './wrapWithSimpleWrapper';
@@ -282,4 +283,10 @@ export function simulateError(
282283

283284
export function fakeDynamicImport(moduleToImport) {
284285
return Promise.resolve({ default: moduleToImport });
286+
287+
export function getMaskedContext(contextTypes, unmaskedContext) {
288+
if (!contextTypes || !unmaskedContext) {
289+
return {};
290+
}
291+
return fromEntries(Object.keys(contextTypes).map(key => [key, unmaskedContext[key]]));
285292
}

packages/enzyme-example-mocha/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"eslint-config-airbnb": "^17.1.0",
2626
"eslint-plugin-import": "^2.14.0",
2727
"eslint-plugin-jsx-a11y": "^6.1.2",
28-
"eslint-plugin-react": "^7.11.1",
28+
"eslint-plugin-react": "^7.12.3",
2929
"espree": "^4.1.0",
3030
"in-publish": "^2.0.0",
3131
"jsdom": "^11.5.1",

packages/enzyme-test-suite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint-plugin-import": "^2.14.0",
5353
"eslint-plugin-jsx-a11y": "^6.1.2",
5454
"eslint-plugin-mocha": "^5.2.0",
55-
"eslint-plugin-react": "^7.11.1",
55+
"eslint-plugin-react": "^7.12.3",
5656
"react-is": "^16.7.0"
5757
}
5858
}

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

+24
Original file line numberDiff line numberDiff line change
@@ -4536,6 +4536,30 @@ describe('shallow', () => {
45364536
expect(wrapper.context().name).to.equal(context.name);
45374537
expect(wrapper.context('name')).to.equal(context.name);
45384538
});
4539+
4540+
it('filters context to childContextTypes', () => {
4541+
class Bar extends React.Component {
4542+
render() {
4543+
return <div />;
4544+
}
4545+
}
4546+
Bar.contextTypes = {
4547+
name: PropTypes.string,
4548+
};
4549+
class Foo extends React.Component {
4550+
render() {
4551+
return (
4552+
<div>
4553+
<Bar />
4554+
</div>
4555+
);
4556+
}
4557+
}
4558+
4559+
const context = { name: 'foo', hello: 'world' };
4560+
const wrapper = shallow(<Foo />, { context });
4561+
expect(wrapper.find(Bar).dive().context()).to.eql({ name: 'foo' });
4562+
});
45394563
});
45404564

45414565
describeIf(is('> 0.13'), 'stateless function components', () => {

packages/enzyme-test-suite/test/adapter-utils-spec.jsx

+33
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect } from 'chai';
33
import {
44
displayNameOfNode,
55
ensureKeyOrUndefined,
6+
getMaskedContext,
67
} from 'enzyme-adapter-utils';
78

89
import './_helpers/setupAdapters';
@@ -82,4 +83,36 @@ describe('enzyme-adapter-utils', () => {
8283
});
8384
});
8485
});
86+
87+
describe('getMaskedContext', () => {
88+
const contextTypes = {
89+
a() {},
90+
c() {},
91+
};
92+
const unmaskedContext = {
93+
a: 1,
94+
b: 2,
95+
c: 3,
96+
};
97+
const falsies = [undefined, null, false, '', NaN, 0];
98+
99+
it('returns an empty object with falsy `contextTypes`', () => {
100+
falsies.forEach((falsy) => {
101+
expect(getMaskedContext(falsy, unmaskedContext)).to.eql({});
102+
});
103+
});
104+
105+
it('returns an empty object with falsy `unmaskedContext`', () => {
106+
falsies.forEach((falsy) => {
107+
expect(getMaskedContext(contextTypes, falsy)).to.eql({});
108+
});
109+
});
110+
111+
it('filters `unmaskedContext` down to `contextTypes`', () => {
112+
expect(getMaskedContext(contextTypes, unmaskedContext)).to.eql({
113+
a: unmaskedContext.a,
114+
c: unmaskedContext.c,
115+
});
116+
});
117+
});
85118
});

0 commit comments

Comments
 (0)