Having issues testing an event in xstate/test #1289
-
Hello! In App.test.js the feedbackMachine has
If I add an event, in this case I called it
Then the test runs and it shows
However, if you change RESET to
Result:
Notice: there is no event RESET in the "form" section I guess my question is, is this by design? Or is it a bug? I am just trying to understand if this is possible with xstate test or if I should be going about this in a different manner. While it might appear having an event go back to the original state doesn't do much, in my case I have an action associated with it, which then returns it to the original state, and want to ensure the action is performed. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
✏️ Please create a CodeSandbox (XState template) reproduction of this. Thanks! |
Beta Was this translation helpful? Give feedback.
-
For each individual path, the testing algorithm is going to avoid cycles whenever possible. If you go:
Then to avoid this from happening:
It remembers that it already visited the To fix this, you need to tell the model that "the default form state" is characteristically different than "the form state after resetting". One simple way to do this is to use nested states: form: {
initial: 'default',
states: {
default: {},
resetted: {}
},
on: {
SUBMIT: [
{
target: "thanks",
cond: (_, e) => e.value.length
}
],
CLOSE: "closed",
RESET: {
target: "form.resetted"
}
}, Then, because |
Beta Was this translation helpful? Give feedback.
For each individual path, the testing algorithm is going to avoid cycles whenever possible. If you go:
Then to avoid this from happening:
It remembers that it already visited the
form
state, and prevents visiting it again (i.e., prevents executingRESET
) to avoid an infinite cycle.To fix this, you need to tell the model that "the default form state" is characteristically different than "the form state after resetting". One simple way to do this is to use nested states: