Skip to content

How to test named delay on machine (without interpretation) #4338

Closed Answered by davidkpiano
FloNeu asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, interpreting the machine would be the best way to test this, but if you don't want to do that, remember that state machines are only affected by events, and that timeout is just an event!

You would have to construct the "xstate.after..." event, which is a bit internal. But here is the implementation in XState v5 beta, to give you an idea:

export function createAfterEvent(delayRef: number | string, id?: string) {
  const idSuffix = id ? `#${id}` : '';
  return { type: `xstate.after(${delayRef})${idSuffix}` } as const;
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@FloNeu
Comment options

@davidkpiano
Comment options

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