-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest 24: enzyme shallow rendered component snapshot is empty #7802
Comments
Also found a similar issue in the wild which someone "fixed" by reverting to Jest 23: https://stackoverflow.com/questions/54419342/jest-enzyme-shallowwrapper-is-empty-when-creating-snapshot |
These are private methods of Enzyme, why would you snapshot them? If you want to snapshot actual component structure from shallow wrapper, you'll need to add a proper serializer like https://github.com/adriantoine/enzyme-to-json |
@thymikee I agree the private methods are unnecessary fluff, but I would expect atleast component name and its props to be a part of the snapshot. I'll try that custom serializer and report back if it resolves the issue. 🙂 |
I've managed to resolve my issue by using the serializer you mentioned. Thanks! 💯Do you think it would be useful to mention somewhere (either in the docs/the changelog/the blogpost) that this previously "accidentally" supported functionality won't work for folks anymore? I know its marked as a breaking change but tbh the impact of that might not be easy to understand for people. |
I think we have some mentions to enzyme in the docs so feel free to add a note about serializer then :) |
I'm still having this issue, despite using Component:
is tested with this code:
but generates an empty
Here is my
|
seems to be producing similar results to
Any concerns about using |
any updates? |
This is something that is not working after the upgrade to `react-scripts`, and also has the benefit of generating more correct and less brittle snapshots. The other option is adding [a proper serializer][1] like [enzyme-to-json][2], but this option also makes things easier to understand without adding another dependency. [1]: jestjs/jest#7802 [2]: https://github.com/adriantoine/enzyme-to-json
For snapshot testing do you guys recommend react-test-renderer's |
Fixes security vulnerabilities reported by npm audit and gives us latest react-scripts features and updates. Update Snapshot tests to work with latest Jest 24 required by react-scripts 3 by using the enzyme-to-json package (see jestjs/jest#7802).
Fixes security vulnerabilities reported by npm audit and gives us latest react-scripts features and updates. Update Snapshot tests to work with latest Jest 24 required by react-scripts 3 by using the enzyme-to-json package (see jestjs/jest#7802).
* Update to react-scripts 3 Fixes security vulnerabilities reported by npm audit and gives us latest react-scripts features and updates. Update Snapshot tests to work with latest Jest 24 required by react-scripts 3 by using the enzyme-to-json package (see jestjs/jest#7802). * Update eslint config * Fix lint errors
Thank you |
try to import |
I am getting empty
Part of jest.config.js :
And here's a sample example of the snapshot test :
Any leads will be helpful! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
Until Jest 23, shallow rendering any component, generated a detailed snapshot (See: https://repl.it/@karanjthakkar/EnzymeShallowWrapperJest23). Due to the changes done in #7448, this use case is now broken and returns an empty snapshot, without even the props(See: https://repl.it/@karanjthakkar/EnzymeShallowWrapperJest24).
To Reproduce
Compare results between v24 and v23 of
pretty-format
for a shallow component render.Expected behavior
From the discussion in #7443, I guess that non enumerable symbolic properties were omitted from the snapshot to reduce the snapshot size and remove unimportant information. However in case of enzyme, all the properties in the shallow-ly wrapped component instance are non-enumerable props: https://github.com/airbnb/enzyme/blob/bcb6fa9e795aefeaab6db608b526a428f45c4b49/packages/enzyme/src/ShallowWrapper.js#L268 -> https://github.com/airbnb/enzyme/blob/bcb6fa9e795aefeaab6db608b526a428f45c4b49/packages/enzyme/src/Utils.js#L273 As such, I'm unsure if you would like to consider this as a bug in Jest or something that Enzyme should be fixing.
Link to repl or repo (highly encouraged)
Working with Jest 23: https://repl.it/@karanjthakkar/EnzymeShallowWrapperJest23
Broken with Jest 24: https://repl.it/@karanjthakkar/EnzymeShallowWrapperJest24
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: