or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-7/

HTTP Mock Harness

Create a tiny helper that registers predictable HTTP/HTTPS responses for a single service base URL so integration-style tests can call the service without leaving the process. The helper should define single-use interceptors per path and HTTP verb, and expose a way to verify that every expected call was exercised.

Capabilities

Configurable GET responses

  • After registering a GET stub for a path, a single GET request to that path on the base URL returns the registered JSON body and status code (defaulting to 200). Subsequent requests should fail unless another stub is registered. @test

Body-matching POST responses

  • When a POST stub specifies an expected JSON payload, a POST request with that body receives the provided response and status (defaulting to 201); mismatched bodies are rejected with a clear error response. @test

Consumption verification

  • After performing all registered requests, calling assertAllConsumed throws an error that lists any paths or verbs that were not exercised; calling reset clears all registrations and pending expectations for a fresh run. @test

Implementation

@generates

API

export function createHttpMockHarness(baseUrl) {
  return {
    registerGet(path, responseBody, statusCode = 200) {},
    registerPost(path, expectedBody, responseBody, statusCode = 201) {},
    assertAllConsumed() {},
    reset() {},
  };
}

Dependencies { .dependencies }

nock { .dependency }

HTTP interception library for mocking HTTP/HTTPS requests during tests.