Skip to content

Having issues testing an event in xstate/test #1289

Discussion options

You must be logged in to vote

For each individual path, the testing algorithm is going to avoid cycles whenever possible. If you go:

CLICK_BAD -> form -> REST -> form

Then to avoid this from happening:

form -> RESET -> form -> RESET -> form

It remembers that it already visited the form state, and prevents visiting it again (i.e., prevents executing RESET) 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:

      form: {
        initial: 'default',
        states: {
          default: {},
          resetted: {}
        },
        on: {
          SUBMIT: [

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ssuttoplunz
Comment options

Comment options

You must be logged in to vote
1 reply
@ssuttoplunz
Comment options

Answer selected by ssuttoplunz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants