Skip to content

How to use test filters without triggering "obsolete snapshot" #7106

Answered by hi-ogawa
jasonkuhrt asked this question in Q&A
Discussion options

You must be logged in to vote

I thought this is a limitation since we cannot track what's the snapshot until toMatchSnapshot("my-name"), but I think we can probably apply a same heuristics as how we handle toMatchSnapshot() which uses auto-icremented number.
(EDIT: oh wait, toMatchSnapshot() actually has the same behavior... 😢)

https://stackblitz.com/edit/vitest-dev-vitest-mitcgkkj?file=test%2F__snapshots__%2Fbasic.test.ts.snap

import { expect, test } from 'vitest';

test('x test', () => {
  expect(0).toMatchSnapshot();  // generates `x test 1`
  expect(0).toMatchSnapshot();  // generates `x test 2`  // when first one fails `x test 2` is considered obsolete
});

test('y test', () => {
  expect(0).toMatchSnapshot('foo'); 

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jasonkuhrt
Comment options

@jasonkuhrt
Comment options

@hi-ogawa
Comment options

Answer selected by jasonkuhrt
@hi-ogawa
Comment options

@jasonkuhrt
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants