[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.

fix(browser): hide injected data-testid attributes (#9503)

authored by

Vladimir and committed by
GitHub
(Jan 22, 2026, 6:37 PM +0100) c8d2c411 e1b95120

+18
+8
test/browser/test/snapshot.test.ts
··· 12 12 await expect('my snapshot content') 13 13 .toMatchFileSnapshot('./__snapshots__/custom/my_snapshot') 14 14 }) 15 + 16 + test('vitest attribute is hidden', () => { 17 + const div = document.createElement('div') 18 + div.setAttribute('data-testid', '__vitest_1__') 19 + expect(div).toMatchInlineSnapshot(` 20 + <div /> 21 + `) 22 + })
+10
packages/pretty-format/src/plugins/lib/markup.ts
··· 23 23 return keys 24 24 .map((key) => { 25 25 const value = props[key] 26 + // hidden injected value that should not be printed 27 + if ( 28 + typeof value === 'string' 29 + && value[0] === '_' 30 + && value.startsWith('__vitest_') 31 + && value.match(/__vitest_\d+__/) 32 + ) { 33 + return '' 34 + } 35 + 26 36 let printed = printer(value, config, indentationNext, depth, refs) 27 37 28 38 if (typeof value !== 'string') {