Skip to content

Having a \r in the snapshot output always fails #2969

@Swatinem

Description

@Swatinem

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When using snapshot testing with the react-test-renderer, rendering some innerHTML containing \r leads to unstable snapshots

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

Running the following test will always fail once you have created a snapshot

import React from "react";
import renderer from "react-test-renderer";

const renderToString = element => renderer.create(element);

it("should handle \\r in a stable manner", () => {
	const el = (<div
		dangerouslySetInnerHTML={{__html: "a\r\nb\r\nc"}} />);
	expect(renderToString(el)).toMatchSnapshot();
});
 FAIL  lib/__tests__/cr.test.js
  ● should handle \r in a stable manner

    Error
      Error: expect(value).toMatchSnapshot()
      
      Received value does not match stored snapshot 1.
      
      - Snapshot
      + Received
      
       <div
         dangerouslySetInnerHTML={
           Object {
      -      "__html": "a
      -    b
      +      "__html": "a
      +    b
           c",
           }
         }
       />
      at Object.<anonymous> (lib/__tests__/cr.test.js:9:29)

What is the expected behavior?

Test should succeed :-)

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

Jest 19, on Archlinux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions