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

fix: strip added indent in error inline snapshots #10217

Merged
merged 4 commits into from
Jul 3, 2020
Merged

fix: strip added indent in error inline snapshots #10217

merged 4 commits into from
Jul 3, 2020

Conversation

pmmmwh
Copy link
Contributor

@pmmmwh pmmmwh commented Jun 28, 2020

Summary

Currently, jest-snapshot does not strip added white space characters when comparing inline snapshots for errors. Test will pass on the first run (when the snapshot is written), but will fail in any subsequent runs. This mainly only affects errors with multi-line messages.

Test plan

Run this code (I'm happy to move this into a test case if required):

it('should pass', () => {
  // This will fail when the snapshot is written
  expect(() => {
    throw new Error(['Line 1', 'Line 2'].join('\n'));
  }).toThrowErrorMatchingInlineSnapshot();
});

Before the change, the test fails.
It passes afterwards.

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.

Thanks! Could you add a test as well? The test added in #8492 might serve as inspiration

@pmmmwh
Copy link
Contributor Author

pmmmwh commented Jul 2, 2020

@SimenB I've added tests - please check if you think it's appropriate!

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.

Just run prettier and it should be good to go 👍

@pmmmwh
Copy link
Contributor Author

pmmmwh commented Jul 3, 2020

I think I've fixed everything.
The failed test is unrelated to this PR and I'm not sure why it's failing either ...

@SimenB SimenB merged commit 1d8285c into jestjs:master Jul 3, 2020
@SimenB
Copy link
Member

SimenB commented Jul 3, 2020

Thanks!

@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
@pmmmwh pmmmwh deleted the fix/error-inline-snapshots branch May 11, 2021 13:18
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