brick.ts

@brickkit/core/testing

createTestApp: an app per test with a typed client and a cleanup.

llms.txt

@brickkit/core/testing exports 3 names: 1 function, 2 interfaces.

import { createTestApp } from "@brickkit/core/testing";

Functions

FunctionDescription
createTestAppBuild an app for a test, with a typed client and a cleanup.

createTestApp

function createTestApp<
  TContract extends Record<string, any> = Record<string, any>,
>(
  options: TestAppOptions<TContract> | (() => TestAppOptions<TContract>),
): TestApp<TContract>

Build an app for a test, with a typed client and a cleanup. Pass a function to define the services inside it: the global registry is emptied first, so the app sees only what that function defines.

Parameters

NameTypeDescription
optionsTestAppOptions<TContract> | (() => TestAppOptions<TContract>)

Returns TestApp<TContract>

Example

const { client, cleanup } = createTestApp(() => {
  const orders = defineService("orders");
  const ship = orders.action({ name: "ship", execute: () => "shipped" });
  return { services: [orders], contract: { orders: { ship } } };
});
expect(await client.orders.ship()).toBe("shipped");
await cleanup();

Source: packages/core/src/testing.ts:35

Interfaces

TestApp

interface TestApp<TContract>

Properties

NameTypeDescription
appBrickApp
clientBrickClient<TContract>Typed client whose requests go straight to app.handle, without a port.

Methods

NameTypeDescription
fetchfetch(path: string | URL, init?: RequestInit): Promise<Response>fetch against the app: await fetch("/api/orders/ship", { method: "POST" }).
cleanupcleanup(): Promise<void>Stops the app if it was listening, stops its events hub, and empties the global registry.

Source: packages/core/src/testing.ts:11

TestAppOptions

interface TestAppOptions<TContract> extends CreateServerOptions

Properties

NameTypeDescription
contract?TContractActions (or a generated contract) the typed client calls, e.g. { orders: { ship } }.

Source: packages/core/src/testing.ts:6

On this page

Generated from the JSDoc above each export. Edit the comment there.