-
-
Notifications
You must be signed in to change notification settings - Fork 178
jest-react-fela | jest-fela-bindings: Support snapshotting in both jsdom and node environments
#903
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
Merged
robinweser
merged 10 commits into
robinweser:master
from
alizeait:jest-support-jsdom-node
Jul 4, 2022
+678
−214
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
af6ef13
Update lockfile
alizeait c3f3cee
Support snapshots in both `jsdom` and `node` environments
alizeait c7d0127
Revert sync `createSnapshot` changes
alizeait cd59afe
Create async `createAsyncSnapshotFactory`
alizeait 9d62105
Create async `createSnapshotAsync`
alizeait 9d2d017
Move shared code to utils
alizeait 279733d
Update babel config and test `jest-react-fela`
alizeait 537b33d
Add React 18 alias
alizeait fd31dd0
Test `node` environment
alizeait 8832312
Test jsdom React 18 environment
alizeait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is, that this is not going to work with React 18 which is now the stable release. You‘ll get a „render is deprecated“ warning for every snapshot 😕
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, how about we either
rendercreateSnapshotto decide between render/createRoot, this can be helpful if people are on React 18 and still using renderThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think 2 separate exports in the same package would be my preferred way.
I tried it before, but I couldn't get React 18 with
createRootto output any markup for jest since it renders async now and thus one would have to await the snapshot in every test instead.TBH I think the current
renderToStaticMarkupis all you need for snapshots. I'd even argue that snapshots with jsdom logic in it are out of scope for component snapshot tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem now is the usage of
useLayoutEffecton the server. The recommended way by the React team is to replaceuseLayoutEffectwithuseEffectserver-side like:The problem with using
renderToStaticMarkupin a jsdom environment is that the above snippet would returnuseLayoutEffectsince window is defined in jsdom and React will complain about using useLayoutEffect server-side