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

Jest ignores obsolete file snapshots if there are inline snapshots #6655

Closed
vlad-zhukov opened this issue Jul 7, 2018 · 6 comments Β· Fixed by #6773
Closed

Jest ignores obsolete file snapshots if there are inline snapshots #6655

vlad-zhukov opened this issue Jul 7, 2018 · 6 comments Β· Fixed by #6773

Comments

@vlad-zhukov
Copy link

πŸ› 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.

@rogeliog
Copy link
Contributor

rogeliog commented Jul 8, 2018

Thanks for reporting! This is a great point, I'm also able to reproduce.

I agree that it should mark the snapshot file as obsolete if it is not used anymore.

@SimenB
Copy link
Member

SimenB commented Jul 8, 2018

/cc @azz

@azz
Copy link
Contributor

azz commented Jul 8, 2018

Huh, I thought I tested that scenario, will be good to add an integration test for it once fixed.

@tiendq
Copy link
Contributor

tiendq commented Jul 11, 2018

I've never used toMatchInlineSnapshot, when I tried it yesterday tests even failed until I added prettier and update jest. Was toMatchInlineSnapshot just added recently? if someone tell me its commit link?

Thanks,

@azz
Copy link
Contributor

azz commented Jul 11, 2018

#6380 & https://github.com/facebook/jest/releases/tag/v23.3.0

@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants