Skip to content

Instantly share code, notes, and snippets.

@lachenmayer
Created November 16, 2016 15:27
Show Gist options
  • Save lachenmayer/38ac97b07ad761643ed525165ea8b0f9 to your computer and use it in GitHub Desktop.
Save lachenmayer/38ac97b07ad761643ed525165ea8b0f9 to your computer and use it in GitHub Desktop.
Jest carriage return bug

To reproduce:

  1. Run ./node_modules/.bin/jest - a snapshot is created in ./__snapshots__/
  2. Run ./node_modules/.bin/jest again.

Expected:

The test should pass.

Actual:

The test fails, as follows:

 FAIL  ./bug.test.js
  ● carriage returns are preserved

    Error
      Error: expect(value).toMatchSnapshot()
      
      Received value does not match stored snapshot 1.
      
      - Snapshot
      + Received
      
      @@ -1,7 +1,7 @@
       <div
         dangerouslySetInnerHTML={
           Object {
      -      "__html": "foo
      +      "__html": "foo
           bar",
           }
         } />
      at Object.<anonymous>.test (bug.test.js:7:16)
      at process._tickCallback (internal/process/next_tick.js:103:7)

  ✕ carriage returns are preserved (13ms)

Snapshot Summary
 › 1 snapshot test failed in 1 test suite. Inspect your code changes or re-run with `-u` to update them.

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   1 failed, 1 total
Time:        0.983s, estimated 1s
Ran all test suites.

The snapshot looks like this:

exports[`test carriage returns are preserved 1`] = `
<div
  dangerouslySetInnerHTML={
    Object {
      "__html": "foo
    bar",
    }
  } />
`;
const React = require('react')
const renderer = require('react-test-renderer')
test('carriage returns are preserved', () => {
const element = React.createElement('div', {dangerouslySetInnerHTML: {__html: "foo\r\nbar"}})
const tree = renderer.create(element)
expect(tree).toMatchSnapshot()
})
{
"dependencies": {
"jest": "^17.0.2",
"react": "^15.4.0",
"react-test-renderer": "^15.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment