You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Fixtures default to strict types. Generated modules import response types from `@api/types.gen` and use a `satisfies` clause to ensure compatibility.
26
25
- Make sure `tsconfig.json` includes: `"paths": { "@api/*": ["./src/generated/*"] }`.
26
+
27
+
## Test-Scoped Overrides with AutoAPIMock
28
+
29
+
Each fixture is wrapped in `AutoAPIMock<T>`, which provides test-scoped override capabilities.
30
+
31
+
### Fixture Structure
32
+
33
+
Generated fixtures use named exports with a consistent naming convention:
// Reset to default behavior (called automatically before each test)
94
+
reset():this;
95
+
96
+
// Internal handler used by MSW (don't call directly)
97
+
generatedHandler:HttpResponseResolver;
98
+
}
99
+
```
100
+
101
+
### Override Function
102
+
103
+
The override function receives:
104
+
1.`data: T` - The default fixture data (useful for partial modifications)
105
+
2.`info: ResponseResolverInfo` - MSW request info (request, params, cookies)
106
+
107
+
Return a `Response` object (use `HttpResponse.json()` from MSW).
108
+
109
+
### Automatic Reset
110
+
111
+
Overrides are automatically reset before each test via `beforeEach()` in `src/mocks/test.setup.ts`. You don't need to manually reset mocks between tests.
112
+
113
+
### Using Default Data in Overrides
114
+
115
+
Access the default fixture data to make partial modifications:
116
+
117
+
```typescript
118
+
mockedGetRegistryV01Servers.override((data) =>
119
+
HttpResponse.json({
120
+
...data,
121
+
servers: data.servers?.slice(0, 1), // Keep only first server
122
+
})
123
+
);
124
+
```
125
+
126
+
### Accessing Request Info
127
+
128
+
Use the `info` parameter to vary responses based on request:
0 commit comments