diff --git a/test/snapshots/test/domain-inline.test.ts b/test/snapshots/test/domain-inline.test.ts index b40ed4004..cc8e82a23 100644 --- a/test/snapshots/test/domain-inline.test.ts +++ b/test/snapshots/test/domain-inline.test.ts @@ -61,6 +61,7 @@ test('domain inline snapshot', async () => { // edit test values: score '999' -> '42' (regex still matches), // status 'active' -> 'inactive' (literal mismatch) editFile(testFile, s => s + .replace(`name: 'alice',`, ``) .replace(`score: '999'`, `score: '42'`) .replace(`status: 'active'`, `status: 'inactive'`)) @@ -68,7 +69,26 @@ test('domain inline snapshot', async () => { result = await runVitest({ root, update: 'none' }) expect(result.stderr).toMatchInlineSnapshot(` " - ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯ + + FAIL basic.test.ts > all literal + Error: Snapshot \`all literal 1\` mismatched + + - Expected + + Received + + - name=alice + age=30 + + ❯ basic.test.ts:5:26 + 3| + 4| test('all literal', () => { + 5| expect({ age: '30' }).toMatchKvInlineSnapshot(\` + | ^ + 6| name=alice + 7| age=30 + + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯ FAIL basic.test.ts > with regex Error: Snapshot \`with regex 1\` mismatched @@ -89,14 +109,16 @@ test('domain inline snapshot', async () => { 13| name=bob 14| score=/\\\\d+/ - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯ " `) expect(result.errorTree()).toMatchInlineSnapshot(` Object { "basic.test.ts": Object { - "all literal": "passed", + "all literal": Array [ + "Snapshot \`all literal 1\` mismatched", + ], "empty snapshot": "passed", "with regex": Array [ "Snapshot \`with regex 1\` mismatched", @@ -123,10 +145,7 @@ test('domain inline snapshot', async () => { // score regex preserved, status updated to 'inactive' expect(readInlineSnapshots(testFile)).toMatchInlineSnapshot(` " - expect({ name: 'alice', age: '30' }).toMatchKvInlineSnapshot(\` - name=alice - age=30 - \`) + expect({ age: '30' }).toMatchKvInlineSnapshot(\`age=30\`) expect({ name: 'bob', score: '42', status: 'inactive' }).toMatchKvInlineSnapshot(\` name=bob diff --git a/test/snapshots/test/domain.test.ts b/test/snapshots/test/domain.test.ts index bcc4a8144..0fc2a315e 100644 --- a/test/snapshots/test/domain.test.ts +++ b/test/snapshots/test/domain.test.ts @@ -80,6 +80,7 @@ test('domain snapshot', async () => { // edit test editFile(testFile, s => s + .replace(`name: 'alice',`, ``) .replace(`score: '999'`, `score: '42'`) .replace(`status: 'active'`, `status: 'inactive'`)) @@ -88,7 +89,26 @@ test('domain snapshot', async () => { result = await runVitest({ root, update: 'none' }) expect(result.stderr).toMatchInlineSnapshot(` " - ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯ + + FAIL basic.test.ts > all literal + Error: Snapshot \`all literal 1\` mismatched + + - Expected + + Received + + - name=alice + age=30 + + ❯ basic.test.ts:5:26 + 3| + 4| test('all literal', () => { + 5| expect({ age: '30' }).toMatchKvSnapshot() + | ^ + 6| }) + 7| + + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯ FAIL basic.test.ts > with regex Error: Snapshot \`with regex 1\` mismatched @@ -109,14 +129,16 @@ test('domain snapshot', async () => { 10| }) 11| - ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯ + ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯ " `) expect(result.errorTree()).toMatchInlineSnapshot(` Object { "basic.test.ts": Object { - "all literal": "passed", + "all literal": Array [ + "Snapshot \`all literal 1\` mismatched", + ], "empty snapshot": "passed", "with regex": Array [ "Snapshot \`with regex 1\` mismatched", @@ -145,7 +167,6 @@ test('domain snapshot', async () => { "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[\`all literal 1\`] = \` - name=alice age=30 \`; diff --git a/test/snapshots/test/fixtures/domain/basic.ts b/test/snapshots/test/fixtures/domain/basic.ts index bb44b63b5..520f28a28 100644 --- a/test/snapshots/test/fixtures/domain/basic.ts +++ b/test/snapshots/test/fixtures/domain/basic.ts @@ -51,12 +51,13 @@ export const kvAdapter: DomainSnapshotAdapter = { const resolvedLines: string[] = [] let pass = true - for (const [key, actualValue] of Object.entries(captured)) { - const expectedValue = expected[key] - - // non asserted keys are skipped (works as subset match) - if (typeof expectedValue === 'undefined') { - continue; + // iterate on `expected` side so extra key on `actual` side + // is ignored and works as subset match + for (const [key, expectedValue] of Object.entries(expected)) { + const actualValue = captured[key] + if (actualValue === undefined) { + pass = false + continue } // preserve matched pattern for normalized error diff and partial update