xstate icon indicating copy to clipboard operation
xstate copied to clipboard

Bug: @xstate/test pathGenerator is not a function

Open Osky772 opened this issue 2 years ago • 5 comments

Description

.getPaths() doesn't work. https://stately.ai/docs/xstate/model-based-testing/quickstart

My package.json dependencies

"dependencies": {
    "@xstate/test": "^1.0.0-alpha.0",
    "xstate": "^4.38.2"
  },
  "devDependencies": {
    "@babel/core": "7.2.0",
    "parcel-bundler": "^1.6.1"
  }

script.js

import { createTestModel, createTestMachine } from "@xstate/test";

const machine = createTestMachine({
  id: "HUD",
  predictableActionArguments: true,

  initial: "one",

  states: {
    one: {
      on: {
        TWO: "two",
        THREE: "three"
      }
    },

    two: {
      on: {
        ONE: "one",
        THREE: "three"
      }
    },

    three: {
      on: {
        ONE: "one",
        TWO: "two"
      }
    }
  }
});

const model = createTestModel(machine);


console.log(".getPaths()");
console.log(model.getPaths().map((p) => p.description));

Expected result

.getPaths to work

Actual result

It does not work

Reproduction

https://github.com/Osky772/xstate-test-bug

Additional context

No response

Osky772 avatar Aug 29 '23 11:08 Osky772

It doesn't work for any @alpha version of @xstate/test. But somehow in Codesandbox it works https://codesandbox.io/s/xstate-test-path-filtering-forked-fnmqtw?file=/src/index.js

Osky772 avatar Aug 29 '23 11:08 Osky772

Can you try this with @xstate/test@beta?

davidkpiano avatar Sep 27 '23 10:09 davidkpiano

Hi @davidkpiano, we are running into the same issue on @xstate/[email protected]. Also, using the same example repo from above, we see the following TS errors (rename index.js to index.ts):

Type '{ on: { TWO: string; THREE: string; }; }' is missing the following properties from type 'TestStateNodeConfig<MachineContext, AnyEventObject>': type, history, onDone, entry, and 7 more.ts(2740)

gnuyent avatar Sep 27 '23 21:09 gnuyent

I've discovered a bug in the documentation. You should use getShortestPaths and not getPaths. I've read in the Changelog that getPath is an alias of the getShortestPaths so it works the same

Osky772 avatar Sep 28 '23 08:09 Osky772

using getShortestPaths the problem no longer appears

Osky772 avatar Sep 28 '23 08:09 Osky772