Testing
Unit tests for primitives, controllers and resolvers with Bun, type tests for the public API, agent tests with nitro-ui-sdk/testing, and iOS harness tests that mount real native components.
The kit is tested at three levels. Pure logic runs in Bun in milliseconds; the public types are checked by the compiler; native behavior runs inside the example app on the iOS simulator.
Unit tests with Bun
Primitives, controllers, value models and style resolvers have no React or native imports, so they test directly. Tests live in packages/nitro-ui-sdk/test/<slug>.test.ts.
import { expect, test } from "bun:test";
import type { ActionSource } from "../src/core";
import { createSwitchModel } from "../src/components/switch/primitive";
test("Switch keeps the source and respects cancellation", () => {
const sources: ActionSource[] = [];
const model = createSwitchModel(() => ({
defaultValue: false,
onValueChange: (checked, details) => {
sources.push(details.source);
if (!checked) details.preventDefault();
},
}));
expect(model.actions.toggle("agent")).toBe("accepted");
expect(model.actions.toggle("user")).toBe("refused");
expect(model.get()).toBe(true);
expect(sources).toEqual(["agent", "user"]);
});
Run them from the repository root:
pnpm --filter nitro-ui-sdk test # bun test test
pnpm --filter nitro-ui-sdk typecheck # tsc --noEmit, including the type tests
Unit tests run without the native runtime. test/setup.ts (preloaded through bunfig.toml) mocks nitro-ui-glass so theme code loads, and reports glass as unsupported.
51 of 51 catalog families have unit tests in packages/nitro-ui-sdk/test/, alongside shared core, parts, theme, agent and host suites. What each implemented family’s unit tests target: a controlled change that the owner refuses, disabled refusing every source, preventDefault returning refused, one commit per interaction, agent actions with valid and invalid arguments, and stale refs after unmount.
Type tests
test/types/<slug>.tsx files are compiled by typecheck and never run. They pin the public API with @ts-expect-error on mistakes that must not compile:
import { Button } from "nitro-ui-sdk/button";
// @ts-expect-error the label is required
<Button.Root onPress={() => {}} />;
// @ts-expect-error unknown parts are rejected
<Button.Root label="Save" onPress={() => {}} styles={{ icon: () => ({}) }} />;
Agent tests with nitro-ui-sdk/testing
createTestRegistry(confirm?) builds a registry without the native confirmation dialog, and createTestDriver(registry) exposes the agent’s view of it: snapshot, query and act. Pass a fake confirm to approve or decline person-only actions.
Because the public nitro-ui-sdk/agent entry point imports the native confirmation service (which requires nitro-core), Bun unit tests in this repository import action and noArgs from the pure ../src/agent/registry module, while createTestRegistry and createTestDriver come from nitro-ui-sdk/testing:
import { expect, test } from "bun:test";
import { action, noArgs } from "../src/agent/registry";
import { createTestDriver, createTestRegistry } from "nitro-ui-sdk/testing";
test("an agent press needs approval", async () => {
let presses = 0;
const registry = createTestRegistry(() => ({ approved: Promise.resolve(false), cancel() {} }));
const agent = createTestDriver(registry);
registry.setForeground("account");
registry.register("account", [], () => ({
component: "Button",
role: "button",
name: "Delete account",
actions: {
press: action(noArgs, () => {
presses += 1;
return "accepted";
}, { message: "Delete?", approveLabel: "Delete", cancelLabel: "Cancel" }),
},
}));
const [entry] = agent.query({ name: "delete" });
expect(entry?.actions).toEqual([{ name: "press", confirm: true }]);
expect(await agent.act({ steps: [{ ref: entry!.ref, action: "press" }] })).toEqual([{ status: "cancelled" }]);
expect(presses).toBe(0);
});
iOS harness tests
Harness tests mount real components, native hosts included, inside the example app on the simulator with nitro-ui-harness. They live in apps/example/__tests__/<slug>.harness.tsx (51 of 51 catalog families have harness suites).
import { expect, it, render } from "nitro-ui-harness";
import { AgentProvider, createAgentRegistry } from "nitro-ui-sdk/agent";
import { Button, buttonPrimitive } from "nitro-ui-sdk/button";
import { createTestDriver } from "nitro-ui-sdk/testing";
it("presses once through the controller and refuses when disabled", async () => {
const registry = createAgentRegistry();
registry.setForeground("catalog");
const agent = createTestDriver(registry);
const api = buttonPrimitive.createApi();
const view = (disabled: boolean) => (
<AgentProvider registry={registry} route="catalog">
<Button.Root label="Save" api={api} disabled={disabled} onPress={() => {}} />
</AgentProvider>
);
const mounted = await render(view(false));
const [entry] = agent.query({ role: "button", name: "Save" });
expect(await agent.act({ steps: [{ ref: entry!.ref, action: "press" }] })).toEqual([{ status: "accepted" }]);
await mounted.rerender(view(true));
expect(api.current?.press()).toBe("disabled");
await mounted.unmount();
expect(api.current).toBeUndefined();
});
Run them against a booted simulator:
cd apps/example
bun run nitro-ui test --platform ios --device <simulator-udid> button select
# or: pnpm --filter example test:ios --device <simulator-udid>
The trailing arguments are patterns that select harness files. Harness tests build the example app, so they need Xcode and an iOS 26 simulator. Android harness tests are written for some editors but have not run on the development machine.