phone/packages/robot3/test/test-immediate.js
Corey Johnson 27aa62f950 Upgrade robot3 to 1.3.0 for improved TypeScript support
- Bundle robot3 1.3.0 locally (not yet published to npm)
- Fix remaining type inference issues with `as any` casts for invoke() events

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 14:53:11 -08:00

52 lines
1.4 KiB
JavaScript

import { createMachine, guard, interpret, immediate, state, transition } from '../machine.js';
QUnit.module('Immediate', hooks => {
QUnit.test('Will immediately transition', assert => {
let machine = createMachine({
one: state(
transition('ping', 'two')
),
two: state(
immediate('three')
),
three: state()
});
let service = interpret(machine, () => {});
service.send('ping');
assert.equal(service.machine.current, 'three');
});
QUnit.test('Will not reject state when a guard fails', assert => {
let machine = createMachine({
one: state(
transition('ping', 'two')
),
two: state(
immediate('three', guard(() => false)),
transition('next', 'three')
),
three: state()
});
let service = interpret(machine, () => {});
service.send('ping');
assert.equal(service.machine.current, 'two');
service.send('next');
assert.equal(service.machine.current, 'three');
});
QUnit.test('Can immediately transitions past 2 states', assert => {
let machine = createMachine({
one: state(
immediate('two')
),
two: state(
immediate('three')
),
three: state()
});
let service = interpret(machine, () => {});
assert.equal(service.machine.current, 'three', 'transitioned to 3');
assert.ok(service.machine.state.value.final, 'in the final state');
});
});