From harness-claude
Guides use of snapshot testing for stable outputs like serialized JSON, HTML, and error messages using toMatchSnapshot and toMatchInlineSnapshot. Covers selective invocation, updating snapshots, and when to avoid snapshots.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:test-snapshot-patternsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Use snapshot testing selectively for stable outputs, knowing when to avoid it
Use snapshot testing selectively for stable outputs, knowing when to avoid it
it('serializes user data correctly', () => {
const user = formatUser({ id: '1', name: 'Alice', email: '[email protected]' });
expect(user).toMatchSnapshot();
});
First run creates the snapshot file. Subsequent runs compare against it.
it('formats the error message', () => {
const error = formatError({ code: 404, resource: 'User' });
expect(error).toMatchInlineSnapshot(`"User not found (404)"`);
});
Vitest/Jest auto-fills the inline snapshot on first run.
it('creates a user with generated fields', () => {
const user = createUser({ name: 'Alice' });
expect(user).toMatchSnapshot({
id: expect.any(String),
createdAt: expect.any(Date),
});
});
This snapshots the structure but uses matchers for non-deterministic fields.
vitest --update # or vitest -u
Review the diff before committing updated snapshots.
it('generates correct SQL', () => {
const query = buildQuery({ table: 'users', where: { role: 'admin' } });
expect(query).toMatchInlineSnapshot(`
"SELECT * FROM users WHERE role = 'admin'"
`);
});
it('generates correct API response', () => {
const response = buildResponse(testData);
expect(response).toMatchSnapshot(); // Stored in __snapshots__/
});
Avoid snapshots for:
Good snapshot candidates:
Snapshot testing captures the serialized output of a value and compares it against a stored reference. It is a regression detection tool — it tells you when output changes, but not whether the change is correct.
Snapshot workflow:
__snapshots__/ or inline)--update flag and review the diffSnapshot hygiene:
toMatchInlineSnapshot for values under 5 lines — inline snapshots are easier to reviewtoMatchSnapshot vs toMatchInlineSnapshot:
Trade-offs:
https://vitest.dev/guide/snapshot.html
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeCreates and manages snapshot tests for UI components and data using Jest, Vitest, or pytest to detect regressions in rendered output.
Patterns for snapshot testing in .NET applications using Verify. Covers API responses, scrubbing non-deterministic values, custom converters, HTTP response testing, email templates, and CI/CD integration. Use when implementing snapshot tests for API responses, verifying UI component renders, detecting unintended changes in serialization output, or approving public API surfaces.
Provides Jest testing patterns for unit tests, mocks, spies, snapshots, setup/teardown, and matchers including equality, truthiness, numbers, strings, and arrays.