vitest-dev / vitest-dev/vitest
Adding a comment between `toMatchInlineSnapshot` and `()` breaks snapshot updates
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
Description:
This is a bit of an edge case, but I thought I'd report it anyway:
It seems like Vitest is unable to write a snapshot to the file if a comment separates toMatchInlineSnapshot and ().
This had me confused for a minute, because the test runner does not report the failure unless the snapshot is incorrect.
Reproduction
Sandbox: StackBlitz
Example:
import * as vi from 'vitest';
// Repro: type 'u' in the terminal to see the snapshots fail to update
vi.test('snapshot w/ comment between assertion and target node does not write', () => {
vi.expect(
0
).toMatchInlineSnapshot
// This comment breaks snapshot updates
();
});
System Info
System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 127.13 MB / 16.00 GB
Shell: 3.3.1 - /usr/local/bin/fish
Binaries:
Node: 24.4.1 - ~/.local/state/fnm_multishells/46602_1758709423661/bin/node
npm: 11.4.2 - ~/.local/state/fnm_multishells/46602_1758709423661/bin/npm
pnpm: 10.15.1 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 140.0.7339.214
Safari: 17.6
npmPackages:
@vitest/coverage-v8: catalog: => 3.2.4
@vitest/ui: catalog: => 3.2.4
vitest: catalog: => 3.2.4
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the StackBlitz reproduction in test/repro.test.ts and run the snapshot update command described in the issue. Trace the inline snapshot update path for the comment between toMatchInlineSnapshot and (); done means the snapshot updates successfully without requiring the comment to be removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100