Custom Jest Matcher For XState Machine States
import {State} from 'xstate'
declare global {
namespace jest {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Matchers<R> {
toMatchState(state: string): CustomMatcherResult
}
}
}
expect.extend({
toMatchState(state: State<unknown>, value: string) {
return {
pass: state.matches(value),
message: () =>
`Expected
"${JSON.stringify(state.value)}"
state to match
"${JSON.stringify(value)}"`,
}
},
})Last updated