vitest-dev / vitest-dev/vitest

Adding a comment between `toMatchInlineSnapshot` and `()` breaks snapshot updates

Open
#8,632 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3-minor-bug
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.