-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Error: toMatchInlineSnapshot cannot be called multiple times at the same location. #7450
Comments
Technically it wasn't "all was good" since it's broken if you run from a clean state, so that's why it's gone as par #6327, #6332 https://stackblitz.com/edit/vitest-dev-vitest-bdoulsxd?file=test%2Fbasic.test.ts function myTest() {
expect(1 + 1).toMatchInlineSnapshot(`2``2`);
} For this reproduction,
Actually different test files calling |
Hi Hiroshima, you’ve said “
Technically it wasn't "all was good" since it's broken if you run from a
clean state,
”
I understand that you had a bug with the generation and injection of
strings when you ran it in a clean test but I feel that the core value of
this method is to match inline string (even if I type it) breaking the
entire functionality of this use case only for a bug in a utility that
helps it happen is wrong in my opinion.
…On Mon, Feb 10, 2025 at 01:58 Hiroshi Ogawa ***@***.***> wrote:
Technically it wasn't "all was good" since it's broken if you run from a
clean state, so that's why it's gone as par #6327
<#6327>, #6332
<#6332>
https://stackblitz.com/edit/vitest-dev-vitest-bdoulsxd?file=test%2Fbasic.test.ts
function myTest() {
expect(1 + 1).toMatchInlineSnapshot(`2``2`);}
For this reproduction, expect(1 + 1).toEqual(2) is probably the only
choice.
I have a shared test.ts file that is used by multiple test files that are
calling it and it uses toMatchInlineSnapshot.
Actually different test files calling toMatchInlineSnapshot might be a
workaround though
https://stackblitz.com/edit/vitest-dev-vitest-cukpaczk?file=test%2Fshared-test.ts
—
Reply to this email directly, view it on GitHub
<#7450 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD65PUYCA6FQQP4457PT3E32O7TRHAVCNFSM6AAAAABWY4PFRSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNBWGY3DGNBVGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I roger what @noam-honig wrote. If I understand correctly, the root of this was: test("snap", () => {
for (const str of ["foo", "bar"]) {
expect(str).toMatchInlineSnapshot();
// transforms to expect(str).toMatchInlineSnapshot(`"foo"``"bar"`);
}
}); Isn't it more a test("snap", () => {
for (const str of ["foo", "bar"]) {
expect(str).toMatchInlineSnapshot();
// transforms to expect(str).toMatchInlineSnapshot(`"foo"`);
// and fail the second expect
}
}); Or maybe having a waring only at the generation of the transform from a cleanstate is sufficient? |
Describe the bug
I have a shared test.ts file that is used by multiple test files that are calling it and it uses
toMatchInlineSnapshot
.It's a set of standard tests for a database that are executed for each database adapter implementation that I have.
All was great and worked in version 2.0.5. As soon as I updated to version 2.1.9 I started getting the error:
Error: toMatchInlineSnapshot cannot be called multiple times at the same location.
It is the same line of code of test that is executed several times wih multiple test files.
How can I fix rhat to work again?
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-y7wyqdfr?file=test%2Fbasic.test.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: