Jest custom matcher for state.matches()
(with types 😄 )
#3848
tmikeschu
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
On my team we're testing high-level happy/sad paths with React Testing Library, and pushing more of the combinations/edge cases/etc to state machine tests. We'd tried a few different assertion patterns for state values but weren't totally happy with any of them.
expect(.matches()).toBe(true)
Pros
Cons
expect(.value).toStrictEqual()
Pros
Cons
expect(.value).toEqual(expect.objectContaining())
Pros
Cons
expect.objectContaining
What if we had
expect(actor).toMatchState()
?Let's implement it!
Now we have
It would be awesome to have some kind of
@xstate/jest
module but this is a nice quick win you can implement manually. Enjoy!Beta Was this translation helpful? Give feedback.
All reactions