Description
Using the hierarchical state machine example example code with @xstate/test, I changed the stop state to be final in the code.
stop: { type: "final" },
The core logic difference between the two machines is:

machine.js: Sub-state goes into final state. Parent uses event to move to next state (see machine code here)machine-final.js: Sub-state goes into final state. Parent uses onDone to move to the next state (see machine-final code here)Expected Result
reaches state {"red":"wait"} (undefined)
โ via POWER_RESTORED โ PED_COUNTDOWN
reaches state {"red":"stop"} (undefined)
โ via POWER_RESTORED โ PED_COUNTDOWN โ PED_COUNTDOWN (1ms)
Actual Result
reaches state {"red":"wait"} (undefined)
โ via POWER_RESTORED โ PED_COUNTDOWN
Reproduction
I've created a demo repo here).
Additional context
The full jest output is:
FAIL ./machine.test.js
LightMachine Test
โ should have full coverage (1ms)
reaches state "green" (undefined)
โ via (2ms)
reaches state {"red":"blinking"} (undefined)
โ via POWER_OUTAGE (1ms)
reaches state {"red":"walk"} (undefined)
โ via POWER_RESTORED
reaches state "yellow" (undefined)
โ via TIMER
reaches state {"red":"wait"} (undefined)
โ via POWER_RESTORED โ PED_COUNTDOWN
reaches state {"red":"stop"} (undefined)
โ via POWER_RESTORED โ PED_COUNTDOWN โ PED_COUNTDOWN
LightMachine Final Test
โ should have full coverage (8ms)
reaches state "green" (undefined)
โ via
reaches state {"red":"blinking"} (undefined)
โ via POWER_OUTAGE
reaches state {"red":"walk"} (undefined)
โ via POWER_RESTORED
reaches state "yellow" (undefined)
โ via TIMER
reaches state {"red":"wait"} (undefined)
โ via POWER_RESTORED โ PED_COUNTDOWN
โ LightMachine Final Test โบ should have full coverage
Missing coverage for state nodes:
light.red.stop
68 |
69 | it("should have full coverage", () => {
> 70 | return lightModelFinal.testCoverage();
| ^
71 | });
72 | });
73 |
at TestModel.testCoverage (node_modules/@xstate/test/src/index.ts:300:13)
at Object.it (machine.test.js:70:28)
I don't know. But in the case I reported. There is another state missing and it isn't final.
I've got the same issue. Final state on a sub-machine with onDone transition will be not be tested even if meta with test is specified.
I think the issue is not with the final state. It's because it's a transient state which will immediately move on to next state. The same thing happens with on: { '': 'next_state' }
Possible duplicate of #718.
This can now be accomplished in the same way as #718 - by using the filter option in model.testCoverage({ option: ... }) to disregard that state.
https://xstate.js.org/docs/packages/xstate-test/#testmodel-testcoverage-options
Most helpful comment
This can now be accomplished in the same way as #718 - by using the
filteroption inmodel.testCoverage({ option: ... })to disregard that state.https://xstate.js.org/docs/packages/xstate-test/#testmodel-testcoverage-options