@xstate/test - How to parametrize tests? #1632
-
We can parametrize actions, activities, guards and services as a string while writing out the representation of state machine. I really like this pattern and in my all projects I keep the JSON/YAML representation separate from actions JS in their own YAML files. I would like to know if there's a way yet to allow us to parametrize test functions or whether that's on the todo list (not sure where that is). Docs say that const toggleMachine = Machine({
id: 'toggle',
initial: 'inactive',
states: {
inactive: {
on: {
/* ... */
},
meta: {
test: async (page) => {
await page.waitFor('input:checked');
}
}
},
active: {
on: {
/* ... */
},
meta: {
test: async (page) => {
await page.waitFor('input:not(:checked)');
}
}
}
}
}); It would be awesome to write it as (if not already supported): id: toggle
initial: inactive
states:
inactive:
on:
activate: active
meta:
test: test-inactive-state
active:
on:
deactivate: inactive
meta:
test: test-active-state
Or maybe not inside id: toggle
initial: inactive
states:
inactive:
tests:
- test-inactive-state
on:
activate: active
active:
tests:
- test-active-state
on:
deactivate: inactive
And then add those |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'll consider this for the next major version of |
Beta Was this translation helpful? Give feedback.
-
@a-y-u-s-h could u open a new issue about this? It would be easier to track this feature request if it would be an issue |
Beta Was this translation helpful? Give feedback.
I'll consider this for the next major version of
@xstate/test
- seems like a good idea.