question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest.retryTimes() gets confused with snapshots

See original GitHub issue

🐛 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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
palmerj3commented, Mar 1, 2019

Thank you

1reaction
palmerj3commented, Jan 23, 2019

I’ll take a look! Thanks for reporting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
jest-snapshot | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Jest Image Snapshot: A Jest Matcher for Image Comparisons
Jest matcher that performs image comparisons using pixelmatch and behaves just like Jest snapshots do! Very useful for visual regression testing.
Read more >
When To Use Jest Snapshots - Selleo
toMatchSnapshot() and running the test for the first time. When snapshot gets outdated you can replace it with a fresh copy by running...
Read more >
Jest-image-snapshot NPM
Want to get paid for your contributions to jest-image-snapshot ? ... jest.retryTimes(). Jest supports automatic retries on test failures.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found