A server instance with request tracking capabilities.
Wraps MSW's SetupServer with additional methods and properties for tracking and inspecting handled requests. Implements Disposable for automatic cleanup with using syntax.
SetupServer
Disposable
using
const server = createTrackedServer( http.get('/api/users', () => HttpResponse.json([])),);server.listen();await fetch('http://localhost/api/users');// Access tracked requestsconsole.log(server.trackedRequests);// Clear tracking historyserver.clearTrackedRequests();// Type guard markerconsole.log(server.isTrackedServer); // true Copy
const server = createTrackedServer( http.get('/api/users', () => HttpResponse.json([])),);server.listen();await fetch('http://localhost/api/users');// Access tracked requestsconsole.log(server.trackedRequests);// Clear tracking historyserver.clearTrackedRequests();// Type guard markerconsole.log(server.isTrackedServer); // true
{ using server = createTrackedServer( http.get('/api/users', () => HttpResponse.json([])), ); server.listen(); await fetch('http://localhost/api/users'); // server.close() called automatically when block exits} Copy
{ using server = createTrackedServer( http.get('/api/users', () => HttpResponse.json([])), ); server.listen(); await fetch('http://localhost/api/users'); // server.close() called automatically when block exits}
Clears all tracked request history.
Readonly
Type guard marker for identifying tracked servers.
Array of all tracked requests (copies, not live references).
A server instance with request tracking capabilities.
Wraps MSW's
SetupServerwith additional methods and properties for tracking and inspecting handled requests. ImplementsDisposablefor automatic cleanup withusingsyntax.Example
Example: Using "using" syntax (TypeScript 5.2+)