-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
failing toMatch(Inline)Snapshot does not abort test #10888
Comments
Looks like not throwing on mismatch is in fact intended. Though I don't agree with the behavior since it's quite surprising as a long-time jest user. I'm working around it (where the current semantics of function toMatchSpeechInlineSnapshot(recordedSpeech, expectedSpeechSnapshot) {
// Abort test on first mismatch.
// Subsequent actions will be based on an incorrect state otherwise and almost always fail as well.
this.dontThrow = () => {};
} |
Comment seems lost at some point, but it's from https://github.com/facebook/jest/pull/1721/files#diff-a9ba5711853a90677041b9a8ec8e241441b46c9f778da77161d3f94e749e4f7eR63-R67. Not really sure why... Maybe so the count of "failing" and "updated" afterwards match up? @cpojer thoughts on this one? |
TL;DR: Generally, I wouldn't mind being able to tell jest "run the test, and then show me all the failed assertions". This makes sense if you have a single action and multiple assertions that don't necessarily depend on each other. In const container = render(<App />);
const button = container.querySelector('button')
expect(button).toHaveFocus();
expect(button).toHaveText('Click me'); it wouldn't hurt to display all failed expectations instead of only displaying the very first. However, this breaks down once you have tests with multiple actions that are asserted on e.g. const container = render(<App />);
const button = container.querySelector('button')
expect(button).toHaveFocus();
expect(button).toHaveText('Click me');
button.click()
expect(container.querySelector('dialog')).not.toBe(null); where you don't need to check if the dialog is opened when we already couldn't find the In other words, when strictly following the arrange-act-assert pattern matchers don't need to throw but should just report their failure state at the end. But if you do "arrange-act-assert(-act-assert)+" you do want to stop at the first failed assert-block. |
One of the main reasons for doing this in the past was so that we keep Jest running (until something else actually throws) so that snapshots are not reported as obsolete – or removed when |
Yeah, I wouldn't feel comfortable changing it. For my specific use case I need a custom inline snapshot matcher anyway where throwing semantics make more sense. Just want to clarify whether |
Added documentation and a test for |
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. |
🐛 Bug Report
A failing
toMatch(Inline)Snapshot
will not stop the test.To Reproduce
Steps to reproduce the behavior:
expect(...).toMatchSnapshot()
Expected behavior
Test aborts on the failing line just like other matchers (e.g.
toEqual
) behave.Link to repl or repo (highly encouraged)
https://github.com/eps1lon/jest-repro-inline-snapshot-bail
envinfo
The text was updated successfully, but these errors were encountered: