Skip to content
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

Merged
merged 5 commits into from
Aug 20, 2019

Conversation

pedrottimark
Copy link
Contributor

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

@pedrottimark
Copy link
Contributor Author

pedrottimark commented Aug 20, 2019

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');

external without

internal without

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'];

external with

internal with

Copy link
Member

@SimenB SimenB left a 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!! 😀

@SimenB SimenB merged commit bc5c3c7 into jestjs:master Aug 20, 2019
@pedrottimark pedrottimark deleted the removeExtraLineBreaks branch August 21, 2019 14:10
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants