[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

docs: update custom snapshot matcher example (#10169)

authored by

Hiroshi Ogawa and committed by
GitHub
(Apr 21, 2026, 12:54 PM +0200) 271d995b 0e0ff41c

+8 -4
+8 -4
docs/guide/snapshot.md
··· 246 246 const { toMatchFileSnapshot, toMatchInlineSnapshot, toMatchSnapshot } = Snapshots 247 247 248 248 expect.extend({ 249 - toMatchTrimmedSnapshot(received: string, length: number) { 250 - return toMatchSnapshot.call(this, received.slice(0, length)) 249 + toMatchTrimmedSnapshot(received: string) { 250 + return toMatchSnapshot.call(this, received.slice(0, 10)) 251 251 }, 252 252 toMatchTrimmedInlineSnapshot(received: string, inlineSnapshot?: string) { 253 253 return toMatchInlineSnapshot.call(this, received.slice(0, 10), inlineSnapshot) ··· 258 258 }) 259 259 260 260 test('file snapshot', () => { 261 + // create __snapshots__/demo.test.ts with 262 + // > exports[`file snapshot 1`] = `"extra long"` 261 263 expect('extra long string oh my gerd').toMatchTrimmedSnapshot(10) 262 264 }) 263 265 264 266 test('inline snapshot', () => { 265 - expect('extra long string oh my gerd').toMatchTrimmedInlineSnapshot() 267 + expect('super long string oh my gerd').toMatchTrimmedInlineSnapshot(`"super long"`) 266 268 }) 267 269 268 270 test('raw file snapshot', async () => { 269 - await expect('extra long string oh my gerd').toMatchTrimmedFileSnapshot('./raw-file.txt') 271 + // create raw-file.txt with: 272 + // > crazy long 273 + await expect('crazy long string oh my gerd').toMatchTrimmedFileSnapshot('./raw-file.txt') 270 274 }) 271 275 ``` 272 276