// Real world
r15
Testing transitions
Walk every legal path with a tiny generator. Assert that illegal actions are refused. Your test suite gets graph coverage for free.
Code
test('cycle ends where it began', () => {
const m = traffic();
['next', 'next', 'next'].forEach(a => m.go(a));
expect(m.state()).toBe('red');
});
test('cannot stop on red', () => {
const m = traffic();
expect(m.valid_action('stop')).toBe(false);
});
Notes
The graph itself is the contract. Tests stop being about implementation details and start being about which paths through the graph matter to your users.