meinaart / cypress-plugin-snapshots

Plugin for snapshot tests in Cypress.io
MIT License
489 stars 116 forks source link

(bug) toMatchSnapshot() can't handle newline characters "\n" #181

Open tschortsch opened 3 years ago

tschortsch commented 3 years ago

Describe the bug When I call .toMatchSnapshot() on a string which contains newline characters "\n" the snapshot gets saved with newlines inside:

<h1>My Heading</h1>
<div>My Div</div>

When I re-run the test it complains that the snapshot doesn't match the actual content:

"<h1>My Heading</h1>\n<div>My Div</div>"

Diff:

-
-<h1>My Heading</h1>
-<div>My Div</div>
+"<h1>My Heading</h1>\n<div>My Div</div>"

To Reproduce Steps to reproduce the behavior:

  1. Create the following test case:
    context('test with newline', () => {
     it('should match snapshot', () => {
       cy.wrap('<h1>My Heading</h1>\n<div>My Div</div>').toMatchSnapshot();
     });
    });
  2. Run the test to create snapshot
  3. Re-run the test
  4. Snapshot doesn't match

Expected behavior The snapshots should match.

Desktop (please complete the following information):