or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Mock Session Guard

A small helper for managing HTTP mocks that ensures planned interactions are fully exercised and cleaned up between tests.

Capabilities

Plans and verifies expected calls

  • After plan is called with expectations (method, path, status, optional body/headers), runWithMocks executes an async callback that should trigger those requests and returns the callback result once all planned responses were served. @test

Flags unfinished expectations

  • After the callback resolves, calling assertComplete throws an error that lists any expected interactions that were never hit (by method and path). When everything was exercised, it returns silently. @test

Lists pending interactions at any time

  • pending reports the remaining expectations at any moment, shrinking as requests are matched and reaching an empty array when all are fulfilled. @test

Resets lifecycle between runs

  • reset cancels any in-flight or pending mocks and removes interceptors so new plans start clean; after a reset, pending is empty and previous expectations do not influence subsequent runs. @test

Implementation

@generates

API

export type MockExpectation = {
  method: string;
  path: string;
  status: number;
  body?: unknown;
  headers?: Record<string, string>;
};

export class MockSession {
  constructor(baseUrl: string);

  plan(expectations: MockExpectation[]): void;

  pending(): string[];

  assertComplete(): void;

  reset(): void;

  runWithMocks<T>(action: () => Promise<T>): Promise<T>;
}

Dependencies { .dependencies }

nock { .dependency }

HTTP interception used to stage expectations, verify consumption, and clean up network hooks between runs.