Skip to content

Snapshot diff view doesn't render whitespace #2287

@SimenB

Description

@SimenB

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

What is the current behavior?
Adding or removing trailing spaces in a component gives a failing snapshot without showing the diff.

image

If I mark the diff in the terminal I can se it, so it's there, it's just not highlighted by Jest.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.

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

test('renders correctly', () => {
  const tree = renderer.create(
    <div>
      <span>Hello </span>
    </div>,
  ).toJSON();

  expect(tree).toMatchSnapshot();
});

Remove or add a trailing whitespace in the span, and get a failing test, but the diff view doesn't indicate why it failed.

What is the expected behavior?
Adding or removing trailing space is shown like this in my git diff:
image
Something similar would be great

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.

node@6.9.1, yarn@0.18.0, macOS Sierra

jest version = 17.0.3
test framework = jasmine2
config = {
  "moduleFileExtensions": [
    "jsx",
    "js",
    "json"
  ],
  "moduleNameMapper": [
    [
      "^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$",
      "/Users/simen/Development/innfinn-es/config/jest/FileStub.js"
    ],
    [
      "^.+\\.css$",
      "/Users/simen/Development/innfinn-es/config/jest/CSSStub.js"
    ]
  ],
  "setupFiles": [
    "/Users/simen/Development/innfinn-es/config/polyfills.js"
  ],
  "testPathIgnorePatterns": [
    "/Users/simen/Development/innfinn-es/(build|docs|node_modules)/"
  ],
  "testEnvironment": "/Users/simen/Development/innfinn-es/node_modules/jest-environment-jsdom/build/index.js",
  "rootDir": "/Users/simen/Development/innfinn-es",
  "name": "-Users-simen-Development-innfinn-es",
  "testRunner": "/Users/simen/Development/innfinn-es/node_modules/jest-jasmine2/build/index.js",
  "transform": [
    [
      "^.+\\.jsx?$",
      "/Users/simen/Development/innfinn-es/node_modules/babel-jest/build/index.js"
    ]
  ],
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/var/folders/58/x7ryp52n7mxbtkld6lr0bqg00000gn/T/jest",
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "expand": false,
  "globals": {},
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "resetMocks": false,
  "resetModules": false,
  "snapshotSerializers": [],
  "testPathDirs": [
    "/Users/simen/Development/innfinn-es"
  ],
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
  "testURL": "about:blank",
  "timers": "real",
  "transformIgnorePatterns": [
    "/node_modules/"
  ],
  "useStderr": false,
  "verbose": null,
  "watch": true,
  "cache": true,
  "watchman": true
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions