statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.89k stars 1.23k forks source link

Bug: @xstate/test pathGenerator is not a function #4214

Open Osky772 opened 1 year ago

Osky772 commented 1 year ago

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 commented 1 year ago

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

davidkpiano commented 11 months ago

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

gnuyent commented 11 months ago

Hi @davidkpiano, we are running into the same issue on @xstate/test@1.0.0-beta.4. 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)
Osky772 commented 11 months ago

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 commented 11 months ago

using getShortestPaths the problem no longer appears