Closed
Description
Describe the Feature
toBeChecked
/toBePartiallyChecked
are Jest DOM matchers that asserts the state of checkbox input.
Adapting it to our case it would assert the value in any host elements having accessibility role of checkbox
and matching accessiblityState: { checked: boolean | 'mixed' }
prop.
Possible Implementations
Proposed API:
export function toBeChecked(
this: jest.MatcherContext,
element: ReactTestInstance
)
export function toBePartiallyChecked(
this: jest.MatcherContext,
element: ReactTestInstance
)
The matcher should:
- Validate that it is invoked on host element is an accessibility element & has accessibility role of
checkbox
orradio
. - Get the current value from
accessiblityState: { checked: boolean | 'mixed' }
prop. - Check the state of checked:
true
fortoBeChecked
,false
for.not.toBeChecked()
and"mixed"
fortoBePartiallyChecked
Each matcher should have a fairly comprehensive test suite.
Links
toBeChecked
matcher code from Jest DOM: https://github.com/testing-library/jest-dom/blob/main/src/to-be-checked.js