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

test: fix kv domain snapshot example (#10207)

authored by

Hiroshi Ogawa and committed by
GitHub
(Apr 27, 2026, 2:08 PM +0200) e680ffbb 166544e3

+58 -17
+26 -7
test/snapshots/test/domain-inline.test.ts
··· 61 61 // edit test values: score '999' -> '42' (regex still matches), 62 62 // status 'active' -> 'inactive' (literal mismatch) 63 63 editFile(testFile, s => s 64 + .replace(`name: 'alice',`, ``) 64 65 .replace(`score: '999'`, `score: '42'`) 65 66 .replace(`status: 'active'`, `status: 'inactive'`)) 66 67 ··· 68 69 result = await runVitest({ root, update: 'none' }) 69 70 expect(result.stderr).toMatchInlineSnapshot(` 70 71 " 71 - ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ 72 + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯ 73 + 74 + FAIL basic.test.ts > all literal 75 + Error: Snapshot \`all literal 1\` mismatched 76 + 77 + - Expected 78 + + Received 79 + 80 + - name=alice 81 + age=30 82 + 83 + ❯ basic.test.ts:5:26 84 + 3| 85 + 4| test('all literal', () => { 86 + 5| expect({ age: '30' }).toMatchKvInlineSnapshot(\` 87 + | ^ 88 + 6| name=alice 89 + 7| age=30 90 + 91 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯ 72 92 73 93 FAIL basic.test.ts > with regex 74 94 Error: Snapshot \`with regex 1\` mismatched ··· 89 109 13| name=bob 90 110 14| score=/\\\\d+/ 91 111 92 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ 112 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯ 93 113 94 114 " 95 115 `) 96 116 expect(result.errorTree()).toMatchInlineSnapshot(` 97 117 Object { 98 118 "basic.test.ts": Object { 99 - "all literal": "passed", 119 + "all literal": Array [ 120 + "Snapshot \`all literal 1\` mismatched", 121 + ], 100 122 "empty snapshot": "passed", 101 123 "with regex": Array [ 102 124 "Snapshot \`with regex 1\` mismatched", ··· 123 145 // score regex preserved, status updated to 'inactive' 124 146 expect(readInlineSnapshots(testFile)).toMatchInlineSnapshot(` 125 147 " 126 - expect({ name: 'alice', age: '30' }).toMatchKvInlineSnapshot(\` 127 - name=alice 128 - age=30 129 - \`) 148 + expect({ age: '30' }).toMatchKvInlineSnapshot(\`age=30\`) 130 149 131 150 expect({ name: 'bob', score: '42', status: 'inactive' }).toMatchKvInlineSnapshot(\` 132 151 name=bob
+25 -4
test/snapshots/test/domain.test.ts
··· 80 80 81 81 // edit test 82 82 editFile(testFile, s => s 83 + .replace(`name: 'alice',`, ``) 83 84 .replace(`score: '999'`, `score: '42'`) 84 85 .replace(`status: 'active'`, `status: 'inactive'`)) 85 86 ··· 88 89 result = await runVitest({ root, update: 'none' }) 89 90 expect(result.stderr).toMatchInlineSnapshot(` 90 91 " 91 - ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ 92 + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯ 93 + 94 + FAIL basic.test.ts > all literal 95 + Error: Snapshot \`all literal 1\` mismatched 96 + 97 + - Expected 98 + + Received 99 + 100 + - name=alice 101 + age=30 102 + 103 + ❯ basic.test.ts:5:26 104 + 3| 105 + 4| test('all literal', () => { 106 + 5| expect({ age: '30' }).toMatchKvSnapshot() 107 + | ^ 108 + 6| }) 109 + 7| 110 + 111 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯ 92 112 93 113 FAIL basic.test.ts > with regex 94 114 Error: Snapshot \`with regex 1\` mismatched ··· 109 129 10| }) 110 130 11| 111 131 112 - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ 132 + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯ 113 133 114 134 " 115 135 `) 116 136 expect(result.errorTree()).toMatchInlineSnapshot(` 117 137 Object { 118 138 "basic.test.ts": Object { 119 - "all literal": "passed", 139 + "all literal": Array [ 140 + "Snapshot \`all literal 1\` mismatched", 141 + ], 120 142 "empty snapshot": "passed", 121 143 "with regex": Array [ 122 144 "Snapshot \`with regex 1\` mismatched", ··· 145 167 "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html 146 168 147 169 exports[\`all literal 1\`] = \` 148 - name=alice 149 170 age=30 150 171 \`; 151 172
+7 -6
test/snapshots/test/fixtures/domain/basic.ts
··· 51 51 const resolvedLines: string[] = [] 52 52 let pass = true 53 53 54 - for (const [key, actualValue] of Object.entries(captured)) { 55 - const expectedValue = expected[key] 56 - 57 - // non asserted keys are skipped (works as subset match) 58 - if (typeof expectedValue === 'undefined') { 59 - continue; 54 + // iterate on `expected` side so extra key on `actual` side 55 + // is ignored and works as subset match 56 + for (const [key, expectedValue] of Object.entries(expected)) { 57 + const actualValue = captured[key] 58 + if (actualValue === undefined) { 59 + pass = false 60 + continue 60 61 } 61 62 62 63 // preserve matched pattern for normalized error diff and partial update