diff --git a/packages/pretty-format/src/plugins/lib/markup.ts b/packages/pretty-format/src/plugins/lib/markup.ts index 5e34fd17853f..891fb75ee393 100644 --- a/packages/pretty-format/src/plugins/lib/markup.ts +++ b/packages/pretty-format/src/plugins/lib/markup.ts @@ -23,6 +23,16 @@ export function printProps( return keys .map((key) => { const value = props[key] + // hidden injected value that should not be printed + if ( + typeof value === 'string' + && value[0] === '_' + && value.startsWith('__vitest_') + && value.match(/__vitest_\d+__/) + ) { + return '' + } + let printed = printer(value, config, indentationNext, depth, refs) if (typeof value !== 'string') { diff --git a/test/browser/test/snapshot.test.ts b/test/browser/test/snapshot.test.ts index 8098a578776a..8060f4cf5e47 100644 --- a/test/browser/test/snapshot.test.ts +++ b/test/browser/test/snapshot.test.ts @@ -12,3 +12,11 @@ test('file snapshot', async () => { await expect('my snapshot content') .toMatchFileSnapshot('./__snapshots__/custom/my_snapshot') }) + +test('vitest attribute is hidden', () => { + const div = document.createElement('div') + div.setAttribute('data-testid', '__vitest_1__') + expect(div).toMatchInlineSnapshot(` +
+ `) +})