Skip to content

jest.retryTimes() gets confused with snapshotsΒ #7493

@phawxby

Description

@phawxby

πŸ› Bug Report

Each retry of a test with a snapshot is identified as a different snapshot. In addition a snapshot test that eventually passes exits as a test failure (exit code 1).

$ jest snapshot.test.js
 PASS  __tests__/snapshot.test.js
  √ simple

 β€Ί 2 snapshots failed.
Snapshot Summary
 β€Ί 2 snapshots failed from 1 test suite. Inspect your code changes or run `yarn test -u` to update them.

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   2 failed, 1 passed, 3 total
Time:        1.518s
Ran all test suites matching /snapshot.test.js/i.
error Command failed with exit code 1.

To Reproduce

jest-bug.zip

// snapshot.test.js
jest.retryTimes(3);

let count = 0;

test('simple', () => {
    count++;
    const name = count === 3 ? 'pass' : 'fail';
    expect('PASS').toMatchSnapshot(name);
});

Snapshot

// snapshot.test.js.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`simple: fail 1`] = `FAIL`;

exports[`simple: fail 2`] = `"FAIL"`;

exports[`simple: pass 1`] = `"PASS"`;

Expected behavior

Snapshot retries should maintain the same name and should exit with 0 if it eventually passed

Link to repl or repo (highly encouraged)

jest-bug.zip

Run npx envinfo --preset jest

  System:
    OS: Windows 10
    CPU: (16) x64 AMD Ryzen 7 1700 Eight-Core Processor
  Binaries:
    Node: 10.14.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.12.3 - C:\Program Files\nodejs\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

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