Skip to content

Commit 32b994d

Browse files
authored
Merge branch 'master' into issue1916
2 parents 4507396 + aa9828a commit 32b994d

File tree

23 files changed

+740
-38
lines changed

23 files changed

+740
-38
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ matrix:
2828
env: REACT=16
2929
- node_js: "lts/*"
3030
env: REACT=16.8.5 RENDERER=16.8.5
31+
- node_js: "lts/*"
32+
env: REACT=16.8.5 RENDERER=16.8.3
3133
- node_js: "lts/*"
3234
env: REACT=16.8.3
3335
- node_js: "lts/*"
@@ -65,6 +67,10 @@ matrix:
6567
env: KARMA=true REACT=15
6668
- node_js: "6"
6769
env: KARMA=true REACT=16
70+
- node_js: "lts/*"
71+
env: REACT=16.8.5 RENDERER=16.8.3
72+
- node_js: "lts/*"
73+
env: REACT=16.8 RENDERER=16.7
6874
exclude:
6975
- node_js: "6"
7076
env: REACT=0.13

docs/api/ReactWrapper/debug.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Bar() {
3131
return (
3232
<div className="bar">
3333
<span>Non-Foo</span>
34-
<Foo baz="bax" />
34+
<Foo baz="bax" object={{ a: 1, b: 2 }} />
3535
</div>
3636
);
3737
}
@@ -44,13 +44,13 @@ console.log(mount(<Bar id="2" />).debug());
4444

4545
Would output the following to the console:
4646
<!-- eslint-disable -->
47-
```jsx
47+
```text
4848
<Bar id="2">
4949
<div className="bar">
5050
<span>
5151
Non-Foo
5252
</span>
53-
<Foo baz="bax">
53+
<Foo baz="bax" object={{...}}>
5454
<div className="foo">
5555
<span>
5656
Foo
@@ -68,7 +68,7 @@ console.log(mount(<Bar id="2" />).find(Foo).debug());
6868
```
6969
Would output the following to the console:
7070
<!-- eslint-disable -->
71-
```jsx
71+
```text
7272
<Foo baz="bax">
7373
<div className="foo">
7474
<span>
@@ -83,7 +83,7 @@ console.log(mount(<Bar id="2" />).find(Foo).debug({ ignoreProps: true }));
8383
```
8484
Would output the following to the console:
8585
<!-- eslint-disable -->
86-
```jsx
86+
```text
8787
<Foo>
8888
<div>
8989
<span>
@@ -92,3 +92,19 @@ Would output the following to the console:
9292
</div>
9393
</Foo>
9494
```
95+
96+
and:
97+
```jsx
98+
console.log(mount(<Bar id="2" />).find(Foo).debug({ verbose: true }));
99+
```
100+
Would output the following to the console:
101+
<!-- eslint-disable -->
102+
```text
103+
<Foo baz="bax" object={{ a: 1, b: 2 }}>
104+
<div className="foo">
105+
<span>
106+
Foo
107+
</span>
108+
</div>
109+
</Foo>
110+
```

docs/api/ShallowWrapper/debug.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ console when tests are not passing when you expect them to.
88

99
`options` (`Object` [optional]):
1010
- `options.ignoreProps`: (`Boolean` [optional]): Whether props should be omitted in the resulting string. Props are included by default.
11+
- `options.verbose`: (`Boolean` [optional]): Whether arrays and objects passed as props should be verbosely printed.
1112

1213
#### Returns
1314

@@ -21,7 +22,12 @@ function Book({ title, pages }) {
2122
return (
2223
<div>
2324
<h1 className="title">{title}</h1>
24-
{pages && <NumberOfPages pages={pages} />}
25+
{pages && (
26+
<NumberOfPages
27+
pages={pages}
28+
object={{ a: 1, b: 2 }}
29+
/>
30+
)}
2531
</div>
2632
);
2733
}
@@ -56,8 +62,8 @@ console.log(wrapper.debug());
5662
Outputs to console:
5763
```text
5864
<div>
59-
<h1 className="title">Huckleberry Finn</h1>
60-
<NumberOfPages pages="633 pages" />
65+
<h1 className="title">Huckleberry Finn</h1>
66+
<NumberOfPages pages="633 pages" object={{...}}/>
6167
</div>
6268
```
6369

@@ -73,7 +79,25 @@ console.log(wrapper.debug({ ignoreProps: true }));
7379
Outputs to console:
7480
```text
7581
<div>
76-
<h1>Huckleberry Finn</h1>
77-
<NumberOfPages />
82+
<h1>Huckleberry Finn</h1>
83+
<NumberOfPages />
84+
</div>
85+
```
86+
87+
88+
```jsx
89+
const wrapper = shallow((
90+
<Book
91+
title="Huckleberry Finn"
92+
pages="633 pages"
93+
/>
94+
));
95+
console.log(wrapper.debug({ verbose: true }));
96+
```
97+
Outputs to console:
98+
```text
99+
<div>
100+
<h1 className="title">Huckleberry Finn</h1>
101+
<NumberOfPages pages="633 pages" object={{ a: 1, b: 2 }}/>
78102
</div>
79103
```

docs/api/shallow.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ describe('<MyComponent />', () => {
5050
- `options.disableLifecycleMethods`: (`Boolean` [optional]): If set to true, `componentDidMount`
5151
is not called on the component, and `componentDidUpdate` is not called after
5252
[`setProps`](ShallowWrapper/setProps.md) and [`setContext`](ShallowWrapper/setContext.md). Default to `false`.
53-
- `options.wrappingComponent`: (`ComponentType` [optional]): A component that will render as a parent of the `node`. It can be used to provide context to the `node`, among other things. See the [`getWrappingComponent()` docs](ShallowWrapper/getWrappingComponent.md) for an example. **Note**: `wrappingComponent` _must_ render its children.
54-
- `options.wrappingComponentProps`: (`Object` [optional]): Initial props to pass to the `wrappingComponent` if it is specified.
53+
- `options.wrappingComponent`: (`ComponentType` [optional]): A component that will render as a parent of the `node`. It can be used to provide context to the `node`, among other things. See the [`getWrappingComponent()` docs](ShallowWrapper/getWrappingComponent.md) for an example. **Note**: `wrappingComponent` _must_ render its children.
54+
- `options.wrappingComponentProps`: (`Object` [optional]): Initial props to pass to the `wrappingComponent` if it is specified.
55+
- `options.suspenseFallback`: (`Boolean` [optional]): If set to true, when rendering `Suspense` enzyme will replace all the lazy components in children with `fallback` element prop. Otherwise it won't handle fallback of lazy component. Default to `true`. Note: not supported in React < 16.6.
5556

5657
#### Returns
5758

docs/guides/migration-from-2-to-3.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,49 @@ Although this is a breaking change, I believe the new behavior is closer to what
102102
actually expect and want. Having enzyme wrappers be immutable results in more deterministic tests
103103
that are less prone to flakiness from external factors.
104104

105+
### Calling `props()` after a state change
106+
107+
In `enzyme` v2, executing an event that would change a component state (and in turn update props) would return those updated props via the `.props` method.
108+
109+
Now, in `enzyme` v3, you are required to re-find the component; for example:
110+
111+
```jsx
112+
class Toggler extends React.Component {
113+
constructor(...args) {
114+
super(...args);
115+
this.state = { on: false };
116+
}
117+
118+
toggle() {
119+
this.setState(({ on }) => ({ on: !on }));
120+
}
121+
122+
render() {
123+
const { on } = this.state;
124+
return (<div id="root">{on ? 'on' : 'off'}</div>);
125+
}
126+
}
127+
128+
it('passes in enzyme v2, fails in v3', () => {
129+
const wrapper = mount(<Toggler />);
130+
const root = wrapper.find('#root');
131+
expect(root.text()).to.equal('off');
132+
133+
wrapper.instance().toggle();
134+
135+
expect(root.text()).to.equal('on');
136+
});
137+
138+
it('passes in v2 and v3', () => {
139+
const wrapper = mount(<Toggler />);
140+
expect(wrapper.find('#root').text()).to.equal('off');
141+
142+
wrapper.instance().toggle();
143+
144+
expect(wrapper.find('#root').text()).to.equal('on');
145+
});
146+
```
147+
105148
## `children()` now has slightly different meaning
106149

107150
enzyme has a `.children()` method which is intended to return the rendered children of a wrapper.

env.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,20 @@ Promise.resolve()
129129
.map(key => `${key}@${key.startsWith('react') ? reactVersion : peerDeps[key]}`);
130130

131131
if (process.env.RENDERER) {
132-
installs.push(`react-test-renderer@${process.env.RENDERER}`);
132+
// eslint-disable-next-line no-param-reassign
133+
adapterJson.dependencies['react-test-renderer'] = process.env.RENDERER;
133134
}
134135

135136
// eslint-disable-next-line no-param-reassign
136137
testJson.dependencies[adapterName] = adapterJson.version;
137138

138-
return Promise.all([
139+
return writeJSON(adapterPackageJsonPath, adapterJson, true).then(() => Promise.all([
139140
// npm install the peer deps at the root
140141
run('npm', 'i', '--no-save', ...installs),
141142

142143
// add the adapter to the dependencies of the test suite
143144
writeJSON(testPackageJsonPath, testJson, true),
144-
]);
145+
]));
145146
})
146147
.then(() => run('lerna', 'bootstrap', '--hoist=\'react*\''))
147148
.then(() => getJSON(testPackageJsonPath))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class ReactSixteenOneAdapter extends EnzymeAdapter {
326326
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
327327
}
328328
// eslint-disable-next-line react/no-find-dom-node
329-
eventFn(nodeToHostNode(node), mock);
329+
eventFn(adapter.nodeToHostNode(node), mock);
330330
},
331331
batchedUpdates(fn) {
332332
return fn();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class ReactSixteenTwoAdapter extends EnzymeAdapter {
328328
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
329329
}
330330
// eslint-disable-next-line react/no-find-dom-node
331-
eventFn(nodeToHostNode(node), mock);
331+
eventFn(adapter.nodeToHostNode(node), mock);
332332
},
333333
batchedUpdates(fn) {
334334
return fn();

packages/enzyme-adapter-react-16.3/src/ReactSixteenThreeAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class ReactSixteenThreeAdapter extends EnzymeAdapter {
347347
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
348348
}
349349
// eslint-disable-next-line react/no-find-dom-node
350-
eventFn(nodeToHostNode(node), mock);
350+
eventFn(adapter.nodeToHostNode(node), mock);
351351
},
352352
batchedUpdates(fn) {
353353
return fn();

0 commit comments

Comments
 (0)