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>
16 lines
691 B
TypeScript
16 lines
691 B
TypeScript
/**
|
|
* Test-only DSL for the Elm-store idiom (CLAUDE.md #3). A fixture is built by
|
|
* replaying real `Msg`s through the real `reduce` — never by hand-assembling a
|
|
* state object field-by-field. That closes off illegal states the reducer would
|
|
* never actually produce: if a spec can't reach a state via messages, it can't
|
|
* assert on it either.
|
|
*
|
|
* `given(reduce, initial)` partially applies a machine's reducer + starting
|
|
* state; the result is a variadic replay function a spec calls with the exact
|
|
* message sequence a real user/flow would send.
|
|
*/
|
|
export const given =
|
|
<S, M>(reduce: (s: S, m: M) => S, initial: S) =>
|
|
(...msgs: M[]): S =>
|
|
msgs.reduce(reduce, initial);
|