Linearis enforces a layered architecture by mocking exactly one layer deep. The mocking strategy depends on the architectural layer being tested:
Resolver Tests
Resolvers depend on GraphQLClient. Mock the request method of the client.
Service Tests
Services also depend on GraphQLClient. Mock the request method.
Client Tests
Client tests mock the network layer by stubbing the global fetch function.
Common Tests
Functions in common/ are pure and do not require mocks.
// Example: Mocking GraphQLClient for a Resolver or Service
import type { GraphQLClient } from "../../src/client/graphql-client.js";
const client = {
request: vi.fn().mockResolvedValue({
teams: { nodes: [{ id: "uuid-123", key: "ABC" }] },
}),
} as unknown as GraphQLClient;
// Example: Mocking fetch for Client tests
const mockFetch = vi.fn();
vi.stubGlobal("fetch", mockFetch);