Skip to main content

Unit Testing

Hosanna repositories use Vitest for fast, in-process tests of TypeScript views, services, utilities, focus behavior, and platform adapters. Keep a behavior at this level when it does not require a launched application, real input transport, rendered screenshot, or device service.

Write a test

Place a *.test.ts file near the source or in the repository's established test directory:

import { beforeEach, describe, expect, it, vi } from 'vitest';

describe('selection model', () => {
const onChanged = vi.fn();

beforeEach(() => {
onChanged.mockReset();
});

it('notifies when the selected index changes', () => {
const model = createSelectionModel({ onChanged });

model.selectedIndex = 2;

expect(onChanged).toHaveBeenCalledWith(2);
});
});

Use the smallest real collaborators that express the contract. Mock network, clocks, files, or platform boundaries where necessary, and reset mutable state before each case.

Run tests

Use the scripts in the repository's package.json. Hosanna framework and sample repositories generate sources before their normal suite:

npm test

To run one file while developing:

npx vitest run path/to/example.test.ts

Some Hosanna repositories require generated sources or a larger Node heap before direct Vitest collection. Prefer the checked-in npm script when one exists.

When to use a launched test

Move to Integration Testing when the contract depends on application startup, navigation history, focus routing through a real runtime, remote/touch/text input, registry persistence, image readiness, platform transport, or screenshots.

The Regression Testing Overview explains how the launched suite complements unit coverage.

Talk to us