Xstate: @xstate/graph not including final state

Created on 26 Nov 2019  ยท  3Comments  ยท  Source: davidkpiano/xstate

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:

Screenshot-20191125073405-1218x230

  • Test case 1: machine.js: Sub-state goes into final state. Parent uses event to move to next state (see machine code here)
  • Test case 2: 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)
bug โš—๏ธ @xstattest

Most helpful comment

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

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodinhart picture rodinhart  ยท  3Comments

bradwoods picture bradwoods  ยท  3Comments

ifokeev picture ifokeev  ยท  3Comments

pke picture pke  ยท  3Comments

doup picture doup  ยท  3Comments