After writing some tests for a component (which all passed ✅) I ran the entire test suite. Firstly it seems to have added a lifecycles Object too all of my snapshots. Even though I haven't actually changed any other components. On the diff I see this received lines:
+ "lifecycles": Object {
+ "componentDidUpdate": Object {
+ "onSetState": true,
+ },
+ "getDerivedStateFromProps": true,
+ "getSnapshotBeforeUpdate": true,
+ "setState": Object {
+ "skipsComponentDidUpdateOnNullish": true,
+ },
+ },
},
},
+ "attachTo": undefined,
+ "hydrateIn": undefined,
I'm running: Node Version 10.9 and Jest ^22.4.3.
I would expect it just to fail the snapshot from the component I changed. Then update the snapshot and it should work.
Received value does not match stored snapshot 1.
- Snapshot
+ Received
@@ -1,7 +1,6 @@
ShallowWrapper {
- "length": 1,
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <MyComponent
clearSuggestions={[Function]}
fetchSuggestions={[Function]}
id="address-lookup"
@@ -318,9 +317,21 @@
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
+ "lifecycles": Object {
+ "componentDidUpdate": Object {
+ "onSetState": true,
+ },
+ "getDerivedStateFromProps": true,
+ "getSnapshotBeforeUpdate": true,
+ "setState": Object {
+ "skipsComponentDidUpdateOnNullish": true,
+ },
+ },
},
},
+ "attachTo": undefined,
+ "hydrateIn": undefined,
},
}
26 | />
27 | );
> 28 | expect(addressLookupWrapper).toMatchSnapshot();
29 |
30 | addressLookupWrapper.unmount();
31 |
at Object.toMatchSnapshot (src/tests/MyComponent.test.js:28:34)
› 1 snapshot test failed.
This seems like an update to enzyme/react rather than something Jest has done.
I recommend taking a look at https://github.com/adriantoine/enzyme-to-json/blob/master/README.md#enzyme-to-json if you want pretty snapshots from enzyme
@drydenwilliams Did you find the root cause ? I have exactly the same diff in my snapshots.
@Dammmien @drydenwilliams I am also experiencing same issue...wondering if either of you found the root cause.
Have you set up the custom serializer?
Me too, same issue
@Matt-Owens Have you found the reason?
@Matt-Owens @Dammmien
I solve this issue by removing the node_modules, and run yarn install, then generate new yarn.lock and test snapshot.
Before I use npm install, something wrong here ...
@jieliu218 it worked like a charm, thanks !!
@Matt-Owens @Dammmien
I solve this issue by removing the node_modules, and run yarn install, then generate new yarn.lock and test snapshot.
Before I use npm install, something wrong here ...
Same here, thanks 👍
Saved my day @jieliu218
Most helpful comment
@Matt-Owens @Dammmien
I solve this issue by removing the node_modules, and run yarn install, then generate new yarn.lock and test snapshot.
Before I use npm install, something wrong here ...