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

Unintended breaking change in snapshot tests in jest 23? #6262

Closed
robin-drexler opened this issue May 25, 2018 · 3 comments
Closed

Unintended breaking change in snapshot tests in jest 23? #6262

robin-drexler opened this issue May 25, 2018 · 3 comments

Comments

@robin-drexler
Copy link
Contributor

💥 Regression Report

I've upgraded to jest 23 and found the following behavior change when it comes to undefined props in snapshots.

Last working version

v22.4.4
Worked up to version:
v22.4.4

Stopped working in version:
v23

To Reproduce

Consider the following test:

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

const Foo = ({ href, target }) => <a href={href} target={target} />;

describe('<Foo />', () => {
  it('renders snapshot', () => {
    expect(
      renderer.create(<Foo href={'https://github.com/facebook/jest'} />)
    ).toMatchSnapshot();
  });
});

In jest 22 the resulting snapshot was:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Foo /> renders snapshot 1`] = `
<a
  href="https://github.com/facebook/jest"
  target={undefined}
/>
`;

Running the same test in jest 23 produces:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Foo /> renders snapshot 1`] = `
<a
  href="https://github.com/facebook/jest"
/>
`;

The target={undefined} has been removed, causing the test to fail.
I could not find anything related to that in the changelog. Is this an intended change

Expected behavior

Snapshots should look the same as in in jest 22

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 1.556s

  System:
    OS: macOS Sierra 10.12.5
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 9.3.0 - ~/.nvm/versions/node/v9.3.0/bin/node
    Yarn: 1.5.1 - ~/.yarn/bin/yarn
    npm: 6.0.1 - ~/.nvm/versions/node/v9.3.0/bin/npm
  npmPackages:
    jest: ^23.0.0 => 23.0.0
@robin-drexler robin-drexler changed the title Unintended breaking change in snapshot testing in jest 23? Unintended breaking change in snapshot tests in jest 23? May 25, 2018
@SimenB
Copy link
Member

SimenB commented May 25, 2018

It's called out in the changelog as a breaking change. Comes from #6162.

@SimenB SimenB closed this as completed May 25, 2018
@robin-drexler
Copy link
Contributor Author

ooops, overlooked that. Thank you!

@github-actions
Copy link

This issue 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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants