Skip to main content
Version: 3.1

Testing

Operaide supports two complementary testing approaches: Jest for testing Reaktor logic in isolation without deploying anything, and Playwright for end-to-end tests that run against a real browser. For most day-to-day development, Jest is what you will reach for first.

Testing Reaktor Logic with Jest

Jest tests live next to your source files and follow the naming pattern *.test.ts. They are picked up automatically — no manual registration required.

The Core Pattern

To test an Aktor, wrap it with __toReaktorForTest__ and call .get() to evaluate it:

import { __toReaktorForTest__, aktorConst } from '@operaide/aktor';
import { aktorGreet } from './aktorGreet';

test('greets correctly', async () => {
const reaktor = __toReaktorForTest__(
aktorGreet({ name: aktorConst('Alice') })
);

const result = await reaktor.get();
expect(result).toBe('Hello, Alice!');
});
  • aktorConst(value) — supplies a fixed input value
  • __toReaktorForTest__(aktor) — wraps your Aktor for testing
  • .get() — evaluates the Aktor and returns the result

Testing with Changing Inputs

When you need to test how your Aktor responds to different input values, use aktorInput and toAktorInternal:

import { __toReaktorForTest__, aktorInput, toAktorInternal } from '@operaide/aktor';
import { aktorGreet } from './aktorGreet';

test('greets different names', async () => {
const name = toAktorInternal(aktorInput('Alice'));

const reaktor = __toReaktorForTest__(
aktorGreet({ name })
);

expect(await reaktor.get()).toBe('Hello, Alice!');

await name.set('Bob');
expect(await reaktor.get()).toBe('Hello, Bob!');
});
  • aktorInput(initialValue) — creates a mutable input Aktor
  • toAktorInternal(aktor) — unwraps it so you can call .set(newValue)
  • After .set(), the next .get() reflects the new value

Testing Streaming Aktors

If your Aktor streams values incrementally, use .getStream() instead of .get():

import { __toReaktorForTest__, aktorConst } from '@operaide/aktor';
import { aktorSummarizeStream } from './aktorSummarizeStream';

test('streams chunks', async () => {
const reaktor = __toReaktorForTest__(
aktorSummarizeStream({ text: aktorConst('Hello world') })
);

const chunks: string[] = [];
for await (const chunk of reaktor.getStream()) {
chunks.push(chunk);
}

expect(chunks.length).toBeGreaterThan(0);
expect(chunks.join('')).toContain('Hello');
});

.get() still works on streaming Aktors and returns the complete result once the stream is finished.

Running Tests

From your App directory:

npm run test          # run all tests once
npm run test:watch # re-run on file changes

To run a single test file:

npm run test -- aktorGreet.test.ts