@brickkit/core/testing
createTestApp: an app per test with a typed client and a cleanup.
@brickkit/core/testing exports 3 names: 1 function, 2 interfaces.
import { createTestApp } from "@brickkit/core/testing";Functions
| Function | Description |
|---|---|
createTestApp | Build 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
| Name | Type | Description |
|---|---|---|
options | TestAppOptions<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
| Name | Type | Description |
|---|---|---|
app | BrickApp | |
client | BrickClient<TContract> | Typed client whose requests go straight to app.handle, without a port. |
Methods
| Name | Type | Description |
|---|---|---|
fetch | fetch(path: string | URL, init?: RequestInit): Promise<Response> | fetch against the app: await fetch("/api/orders/ship", { method: "POST" }). |
cleanup | cleanup(): 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 CreateServerOptionsProperties
| Name | Type | Description |
|---|---|---|
contract? | TContract | Actions (or a generated contract) the typed client calls, e.g. { orders: { ship } }. |
Source: packages/core/src/testing.ts:6