-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Snapshot tests fail with concurrent execution (Error: Snapshot cannot be used outside of test) #2729
Comments
You need to use "expect" from test context, when using snapshots in concurrent tests: it("test", ({ expect }) => {
expect(1).toMatchSnapshot()
}) I don't know why it worked for you before, but it shouldn't have, and was never intended to work with global expect. |
Interesting. The small case in #551 also uses a global expect vs expect from the test case. Any way to return back to the previous behavior? If not, I'm happy to submit an update to the documentation to make this clearer. |
Do you mean the reproduction? It never worked, and couldn't have worked, because snapshot needs to know information about the current test. If you run tests concurrently, you don't have a reliable way to mark the test as "current", because they are running at the same time. To bypass that, you need to use expect from the context.
Feel free to submit PR with the change using |
Yeah, I was referring to the reproduction in the original report of #551. That case also worked without issues in 0.27.1 and stopped working in 0.27.2. I'll get a PR for the documentation update over. In addition to the snapshot page, I was thinking of updating the concurrent example on the feature page to show it using a context specific expect. |
…oncurrent test close vitest-dev#2729
…oncurrent test close vitest-dev#2729
Describe the bug
As of 0.27.2, concurrent async tests that use snapshots fail with
Error: Snapshot cannot be used outside of test
message. These tests worked fine under 0.27.1.Related tickets from the past
#551
Reproduction
https://stackblitz.com/edit/vitejs-vite-kcqha8?file=package.json,package-lock.json,main.test.jsx&terminal=dev
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: