Skip to content

fix(snapshot): fail test when snapshot assertion is used with test.fails#10090

Open
hi-ogawa wants to merge 8 commits intovitest-dev:mainfrom
hi-ogawa:fix-fails-test-when-snapshot-assertion-is-used-with-test-fails
Open

fix(snapshot): fail test when snapshot assertion is used with test.fails#10090
hi-ogawa wants to merge 8 commits intovitest-dev:mainfrom
hi-ogawa:fix-fails-test-when-snapshot-assertion-is-used-with-test-fails

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Apr 7, 2026

Description

expect.soft handling is a bit annoying 🤔 I ended up with using error.__vitest_test_syntax_error__ to allow communicate between expect/runner/vitest packages basically.

This is likely a breaking change since users can do really weird thing with snapshot.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 7, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a1f4805
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69d4ebb090c3a100096d2052
😎 Deploy Preview https://deploy-preview-10090--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa added this to the 5.0.0 milestone Apr 7, 2026
@hi-ogawa hi-ogawa marked this pull request as ready for review April 7, 2026 11:10
@hi-ogawa hi-ogawa added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Apr 7, 2026
@github-actions

This comment was marked as resolved.

@hi-ogawa hi-ogawa removed the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Apr 7, 2026
@sheremet-va
Copy link
Copy Markdown
Member

This is likely a breaking change since users can do really weird thing with snapshot.

I'm not so sure it's a breaking change. What kind of use cases does this break?

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

hi-ogawa commented Apr 7, 2026

This is likely a breaking change since users can do really weird thing with snapshot.

I'm not so sure it's a breaking change. What kind of use cases does this break?

I removed one test from test/core/test/snapshot.test.ts and that's the one.

@sheremet-va
Copy link
Copy Markdown
Member

This is likely a breaking change since users can do really weird thing with snapshot.

I'm not so sure it's a breaking change. What kind of use cases does this break?

I removed one test from test/core/test/snapshot.test.ts and that's the one.

Oh, I don't think this PR fixes the issue then. I thinktoMatchSnapshot should still work, it just shouldn't update the snapshot

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

hi-ogawa commented Apr 8, 2026

This is likely a breaking change since users can do really weird thing with snapshot.

I'm not so sure it's a breaking change. What kind of use cases does this break?

I removed one test from test/core/test/snapshot.test.ts and that's the one.

Oh, I don't think this PR fixes the issue then. I thinktoMatchSnapshot should still work, it just shouldn't update the snapshot

test.fails outright rejecting snapshot matchers makes sense to me. This is basically same as how we reject expect(...).not.toMatchSnapshot(). Also that's at least what TestSyntaxError should entail. It shouldn't dependent on runtime surrounding.

@sheremet-va
Copy link
Copy Markdown
Member

test.fails outright rejecting snapshot matchers makes sense to me.

Why? The test can have other assertions that fail, and snapshot to pass:

test.fails('test', () => {
  expect(shape).toMatchInlineSnapshot(`{ name: 'Alice' }`)
  expect(otherShape).toEqual({ name: 'Bob' }) // fails! 
})

It should just ignore the snapshot error when vitest tries to update it - at least that's what the issue is.

test.fails('test', () => {
  expect(shape).toMatchInlineSnapshot(`{ name: 'Bob' }`) // fails
})
vitest run -u // should ignore the error in `test.fails`, treat as --update=none in that test

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

hi-ogawa commented Apr 8, 2026

The reason to prefer reject everything is because supporting the case by case can be confusing when users end up reaching such invalid state during the development without directly modifying the test itself to introduce forbidden combination of test.fails + snapshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dont update snapshot inside it.fails

2 participants