Types for xstate stately.ai json files
-
Export your machine from stately.ai as json file
-
Save it as typescript file
export default {
// ...
} as const // make sure add this for properly typings
- Declare your machine as test model
const model = declareTestModel(toggleMachine, {
// your events that change state
events: {
"SET OFF": async () => {
toggle.set(false)
},
"SET ON": async () => {
toggle.set(true)
},
},
// your asserts that check state
expectations: {
OFF: async () => {
expect(toggle.value).toBe(false)
},
ON: async () => {
expect(toggle.value).toBe(true)
},
}
})
- Describe tests with preferred runner
describeWithJest(model) // only jest template for now
Look into tests
folder