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

toMatchSnapshot(filepath) #4231

Closed
vjeux opened this issue Aug 9, 2017 · 7 comments
Closed

toMatchSnapshot(filepath) #4231

vjeux opened this issue Aug 9, 2017 · 7 comments
Assignees

Comments

@vjeux
Copy link
Contributor

vjeux commented Aug 9, 2017

The current jest snapshot tests are annoying in the context of jest (and I presume relay as well) because they put things inside of quotes and add some small wrapper code to make it parse as js and it generates those snapshots in some __ directory.

I've been thinking about this problem for a while and I think I finally have a solution: add the ability to specify the filename as an argument of toMatchSnapshot().

Current

/* file.js */
expect(value).toMatchSnapshot()
/* __snapshots__/file.js.snap */
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`file.js 1`] = `
value
`;

Suggestion

/* file.js */
expect(value).toMatchSnapshot('file.snap')
/* file.snap */
value

Discussion

I'm not 100% sure how to remove unused snapshot files when they are no longer in use.

@cpojer
Copy link
Member

cpojer commented Aug 9, 2017

Yeah, we cannot do this, precisely for the reason you mentioned about consistency between snapshot files and tests. If we had to apply static analysis to get this information, it would break down in a bunch of ways and make this really hard :(

@thymikee
Copy link
Collaborator

thymikee commented Aug 9, 2017

Something that might help: #4183

@vjeux
Copy link
Contributor Author

vjeux commented Aug 9, 2017

I'm happy not having unused snapshot files being removed automatically to be honest.

@vjeux
Copy link
Contributor Author

vjeux commented Aug 9, 2017

Is there a way to observe if jest is running with -u from within a test in order to implement this proposal in userland?

@cpojer
Copy link
Member

cpojer commented Aug 9, 2017

Not currently. I don't think it's reasonable to deploy something at Facebook that doesn't clean up after itself. We'd have multiple thousand snapshot files at FB at this point if we didn't have the consistency check :(

@vjeux vjeux closed this as completed Aug 9, 2017
@igor-dv
Copy link

igor-dv commented Dec 11, 2017

Hey, I've created this matcher that allows specifying snapshot location in the following way:

expect(value).toMatchSpecificSnapshot('path/to/file.snapshot')

Hope it will help.

@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 13, 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

4 participants