Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/pretty-format/src/plugins/lib/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
8 changes: 8 additions & 0 deletions test/browser/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
<div />
`)
})
Loading