Skip to content

Add snapshot testing for generated API response schemas #47

@PAMulligan

Description

@PAMulligan

Description

Add snapshot testing to the `tdd-from-schema` skill so that generated integration tests include response schema snapshots. This catches unintentional response format changes (added/removed fields) that wouldn't fail a status code assertion.

Why

Schema changes in API responses are breaking changes for consumers. Snapshot tests catch these changes automatically and force explicit acknowledgment when the response shape intentionally changes. This complements the existing contract tests.

Acceptance Criteria

  • Add Vitest snapshot testing to the `tdd-from-schema` skill output
  • Generate snapshot tests that capture:
    • Response body structure (keys, not values)
    • Response headers (Content-Type, custom headers)
    • Error response shapes
  • Use `toMatchSnapshot()` for full snapshots
  • Use `toMatchInlineSnapshot()` for critical fields
  • Document how to update snapshots when changes are intentional (`vitest -u`)
  • CI passes

Example

```typescript
it('GET /users/:id response matches schema snapshot', async () => {
const res = await app.request('/v1/users/1');
const body = await res.json();
expect(Object.keys(body.data).sort()).toMatchInlineSnapshot(`
[
"createdAt",
"email",
"id",
"name",
"updatedAt",
]
`);
});
```

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions