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 ignores obsolete file snapshots if there are inline snapshots

See original GitHub issue

🐛 Bug Report

Jest ignores obsolete file snapshots if there are inline snapshots in this test.

To Reproduce

Steps to reproduce the behavior:

test('test', () => {
	expect('foo').toMatchSnapshot();
});
$ jest
 PASS  __tests__/test.js
  ✓ test (3ms)

 › 1 snapshot written.
Snapshot Summary
 › 1 snapshot written from 1 test suite.

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   1 written, 1 total
Time:        2.244s
Ran all test suites.

Change the above test to use inline snapshots:

test('test', () => {
	expect('foo').toMatchInlineSnapshot();
});
$ jest
 PASS  __tests__/test.js
  ✓ test (3ms)

 › 1 snapshot written.
Snapshot Summary
 › 1 snapshot written from 1 test suite.

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   1 written, 1 total
Time:        2.302s
Ran all test suites.

Now both a file and an inline snapshots exists. The file snapshot is completely ignored, Jest doesn’t report that it’s obsolete and doesn’t remove it with jest -u.

Expected behavior

Jest should fail on obsolete snapshots and remove them with jest -u.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
github-actions[bot]commented, May 12, 2021

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.

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 testing: how to ignore part of the snapshot file in ...
the question here: there are some components in my test that have a random values and i don't really care about testing them....
Read more >
Jest - Obsolete snapshots are not detected : WEB-37035
recreated; there are no prompts to update snapshot. When running jest --watch , snapshot is reported to be obsolete;. Ran all test suites...
Read more >
jest snapshot testing example, jest snapshot date, ui snapshot ...
Now both a file and an inline snapshots exists. The file snapshot is completely ignored, Jest doesn't report that it's obsolete and doesn't...
Read more >
What's wrong with snapshot tests. Since snapshot ... - Medium
When you write expect(mycomponent).toMatchSnapshot() , Jest creates a snapshot file, like mytest.spec.js.snap , with all snapshots of your test file. You ...
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