Skip to content

Adding a comment between toMatchInlineSnapshot and () breaks snapshot updates #8632

@ahrjarrett

Description

@ahrjarrett

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions