or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-1/

HTTP Mock Trace Recorder

Capture request traces and unmatched calls for a single HTTP(S) host using a mocking dependency.

Capabilities

Captures unmatched requests

  • When an HTTP request targets the configured host without a matching mock, an unmatched entry with method and full URL is recorded immediately via the mocking layer's unmatched hook. @test

Traces matched requests and replies

  • When a mocked endpoint is invoked, the helper logs both the request and its eventual reply (including status and body summary) in call order using the mocking layer's trace events. @test

Supports teardown

  • Invoking teardown stops all event listeners and removes mocks so later HTTP calls are unaffected, while previously recorded traces remain available. @test

Implementation

@generates

API

/**
 * Creates a tracer for a single base URL using the HTTP mocking dependency.
 *
 * @param {string} baseUrl - Host (with protocol) to intercept.
 * @param {{ allowUnmocked?: boolean }} [options]
 * @returns {{
 *   scope: unknown,
 *   traces: Array<{ type: 'request' | 'replied', method: string, path: string, status?: number, body?: any }>,
 *   unmatched: Array<{ method: string, url: string }>,
 *   mock(method: string, path: string, status: number, body?: any, headers?: Record<string, string>): void,
 *   teardown(): void
 * }}
 */
export function createMockTrace(baseUrl, options);

Dependencies { .dependencies }

nock { .dependency }

Mocks HTTP(S) requests and emits lifecycle events for trace and unmatched requests.