HTTP server mocking and expectations library for Node.js testing environments
67
A helper that configures mocked profile-service HTTP interactions with strict request header expectations and consistent reply headers for tests.
/profile without an Authorization bearer token yields a 401 JSON body and still returns the default response headers. @test/profile with an Authorization bearer token and Accept: application/json returns the stub profile JSON and default response headers. @testX-Env: test, Cache-Control: no-store, a Date header, and a Content-Length matching the body emitted for that mock. @testX-Spoof return a 403 stub immediately and do not satisfy other mocks. @test/profile with valid basic auth and JSON body returns 204, echoes X-Trace-Id from the request into the response headers, and applies default headers; missing auth yields 401. @test@generates
export interface HeaderMocks {
mockProfileRead(token: string, profile: Record<string, unknown>): void;
mockProfileUpdate(credentials: { username: string; password: string }, body: Record<string, unknown>): void;
blockSpoofing(): void;
verifyAll(): void;
reset(): void;
}
export function createHeaderMocks(baseUrl: string): HeaderMocks;Mock HTTP requests and responses for Node tests, including header matching and reply header helpers.
Install with Tessl CLI
npx tessl i tessl/npm-nockdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10