Every machine spec redefined its own throwaway fixture helper (editing1/2/3,
editingWith), hardcoding fields like errors: {} that assert against shapes
the reducer may never actually produce. given(reduce, initial)(...msgs)
(libs/shared/src/testing/machine.ts) replaces them by replaying real Msgs
through the real reduce, so a fixture is provably reachable. Adds the same
idiom for value objects (unwrapOk) and RemoteData (loading/success/failure),
plus intake.acceptance.spec.ts as a worked full-journey example.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
21 lines
779 B
TypeScript
21 lines
779 B
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { machineRemoteData } from './machine-remote-data';
|
|
import { loading, success } from '../testing/remote-data';
|
|
|
|
describe('machineRemoteData', () => {
|
|
it('maps loading → Loading', () => {
|
|
expect(machineRemoteData({ tag: 'loading' })).toEqual(loading());
|
|
});
|
|
|
|
it('maps failed → Failure carrying an Error with the reason', () => {
|
|
const rd = machineRemoteData({ tag: 'failed', reason: 'boom' });
|
|
expect(rd.tag).toBe('Failure');
|
|
if (rd.tag === 'Failure') expect(rd.error.message).toBe('boom');
|
|
});
|
|
|
|
it('maps loaded → Success carrying the whole loaded state', () => {
|
|
const loaded = { tag: 'loaded', foo: 42 } as const;
|
|
expect(machineRemoteData(loaded)).toEqual(success(loaded));
|
|
});
|
|
});
|