Skip to content

feature: implement toBeChecked, toBePartiallyChecked Jest matchers #1457

Closed
@mdjastrzebski

Description

@mdjastrzebski

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:

  1. Validate that it is invoked on host element is an accessibility element & has accessibility role of checkbox or radio.
  2. Get the current value from accessiblityState: { checked: boolean | 'mixed' } prop.
  3. Check the state of checked: true for toBeChecked, false for .not.toBeChecked() and "mixed" for toBePartiallyChecked

Each matcher should have a fairly comprehensive test suite.

Links

Related Issues

#1454

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions