-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to test conditional transitions? #49
Comments
I'm working on a solution for that in |
Thank you very much @hally9k @davidkpiano.
For example: const statechart = {
initial: 'a',
states: {
a: {
on: {
EVENT: {
b: {
cond: extState => extState.shouldPass,
},
},
},
},
b: {},
},
}
const machine = Machine(statechart)
const paths = getShortestPaths(machine)
// { '"a"': [] } |
@MicheleBertoli Can you open an issue so I can track it? |
Sure @davidkpiano, here it is: statelyai/xstate#100. |
Given the following statechart: const statechart = {
initial: 'a',
states: {
a: {
on: {
EVENT: {
b: {
cond: extState => extState.shouldPass,
},
},
},
},
b: {},
},
} and the following component: const Cond = () => (
<React.Fragment>
<State value="a">A</State>
<State value="b">B</State>
</React.Fragment>
) it's now possible to write a test that passes the condition: test('pass', () => {
const extendedState = {
shouldPass: true,
}
const fixtures = {
a: {
EVENT: extendedState,
},
}
testStatechart({ statechart, fixtures, extendedState }, Cond)
}) exports[`cond pass: a 1`] = `"A"`; exports[`cond pass: b 1`] = `"B"`; and one that doesn't: test('fail', () => {
testStatechart({ statechart }, Cond)
}) exports[`cond fail: a 1`] = `"A"`; Thank you very much, @hally9k @davidkpiano. |
This is SUPER awesome. Go team!!! This was the one thing holding our project back from full adoption. Let's go! |
How can I set the
extendedState
for a guarded transition in my testing fixtures?The text was updated successfully, but these errors were encountered: