How to test named delay on machine (without interpretation) #4338
-
I want to test a machine that has a named delay between two states like: With and event transision, for example how can i perform this structural test in a similar manner or do i have to change the approch I am aware that i could interprete the machine and use the simulated clock to test, but try to find Regards, Florian |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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 export function createAfterEvent(delayRef: number | string, id?: string) {
const idSuffix = id ? `#${id}` : '';
return { type: `xstate.after(${delayRef})${idSuffix}` } as const;
} |
Beta Was this translation helpful? Give feedback.
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: