(this: jest.MatcherContext, instance: TestInstance)
| 14 | import { checkHostElement } from './utils'; |
| 15 | |
| 16 | export function toBeChecked(this: jest.MatcherContext, instance: TestInstance) { |
| 17 | checkHostElement(instance, toBeChecked, this); |
| 18 | |
| 19 | if (!isHostSwitch(instance) && !isSupportedAccessibilityElement(instance)) { |
| 20 | throw new ErrorWithStack( |
| 21 | `toBeChecked() works only on host "Switch" instances or accessible instance with "checkbox", "radio" or "switch" role.`, |
| 22 | toBeChecked, |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | return { |
| 27 | pass: computeAriaChecked(instance) === true, |
| 28 | message: () => { |
| 29 | const is = this.isNot ? 'is' : 'is not'; |
| 30 | return [ |
| 31 | matcherHint(`${this.isNot ? '.not' : ''}.toBeChecked`, 'instance', ''), |
| 32 | '', |
| 33 | `Received instance ${is} checked:`, |
| 34 | redent(formatElement(instance), 2), |
| 35 | ].join('\n'); |
| 36 | }, |
| 37 | }; |
| 38 | } |
| 39 | |
| 40 | function isSupportedAccessibilityElement(instance: TestInstance) { |
| 41 | if (!isAccessibilityElement(instance)) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…