-
-
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-snapshot: Remove only the added newlines in multiline snapshots #8859
Conversation
Example pictures baseline at left and improved at right without serializer is enclosed in double quote marks, so baseline and improved both correct: const expected = ['first line', 'second line', ''].join('\n');
const received = ['first line', 'second line'].join('\n'); with serializer which joins array items with newline has no punctuation to stop the over-trim: const expected = ['first line', 'second line', ''];
const received = ['first line', 'second line']; |
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.
What an elegant solution! Thanks!! 😀
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Because a custom serializer might return a string with newlines or spaces at beginning or end,
trim
is not the correct method (pardon pun :) to remove the two newlines that were added at beginning and end of multiline content.Example of the problem: #8850 (comment) and #8850 (comment)
Test plan
Added 7 tests
See also pictures in the following comment for local end-to-end test