Files
github-actions[bot] afeef81d9a deploy: 8b17683d64
2026-07-20 09:16:38 +00:00

1 line
32 KiB
JavaScript

"use strict";(self.rspackChunkwebsite=self.rspackChunkwebsite||[]).push([["7759"],{5826(e,s,n){n.r(s),n.d(s,{default:()=>a});var r=n(4848),i=n(8453),l=n(7425);function o(e){let s={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",span:"span",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.h1,{id:"jest-matchers",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#jest-matchers",children:"#"}),"Jest matchers"]}),"\n",(0,r.jsx)(s.p,{children:"This guide covers the built-in Jest matchers. These matchers make your tests easier to read and work better with accessibility features."}),"\n",(0,r.jsxs)(s.h2,{id:"setup",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#setup",children:"#"}),"Setup"]}),"\n",(0,r.jsxs)(s.p,{children:["No setup needed. Matchers are available when you import from ",(0,r.jsx)(s.code,{children:"@testing-library/react-native"}),"."]}),"\n",(0,r.jsxs)(s.h2,{id:"checking-element-existence",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#checking-element-existence",children:"#"}),"Checking element existence"]}),"\n",(0,r.jsxs)(s.h3,{id:"tobeonthescreen",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobeonthescreen",children:"#"}),(0,r.jsx)(s.code,{children:"toBeOnTheScreen()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsx)(s.code,{children:(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeOnTheScreen"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})})})}),"\n",(0,r.jsx)(s.p,{children:"Checks if an element is attached to the element tree. If you have a reference to an element and it gets unmounted during the test, this assertion will fail."}),"\n",(0,r.jsxs)(s.h2,{id:"element-content",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#element-content",children:"#"}),"Element Content"]}),"\n",(0,r.jsxs)(s.h3,{id:"tohavetextcontent",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tohavetextcontent",children:"#"}),(0,r.jsx)(s.code,{children:"toHaveTextContent()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toHaveTextContent"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" text: string "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" RegExp"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" options"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" exact?"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" boolean;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" normalizer"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" (text"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:") "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" string;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element has the specified text content. Accepts ",(0,r.jsx)(s.code,{children:"string"})," or ",(0,r.jsx)(s.code,{children:"RegExp"}),", with optional ",(0,r.jsx)(s.a,{href:"/docs/api/queries.html#text-match-options",children:"text match options"})," like ",(0,r.jsx)(s.code,{children:"exact"})," and ",(0,r.jsx)(s.code,{children:"normalizer"}),"."]}),"\n",(0,r.jsxs)(s.h3,{id:"tocontainelement",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tocontainelement",children:"#"}),(0,r.jsx)(s.code,{children:"toContainElement()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(container)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toContainElement"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" instance: TestInstance "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" null"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsx)(s.p,{children:"Checks if a container element contains another element."}),"\n",(0,r.jsxs)(s.h3,{id:"tobeemptyelement",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobeemptyelement",children:"#"}),(0,r.jsx)(s.code,{children:"toBeEmptyElement()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsx)(s.code,{children:(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeEmptyElement"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})})})}),"\n",(0,r.jsx)(s.p,{children:"Checks if an element has no child elements or text content."}),"\n",(0,r.jsxs)(s.h2,{id:"checking-element-state",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#checking-element-state",children:"#"}),"Checking element state"]}),"\n",(0,r.jsxs)(s.h3,{id:"tohavedisplayvalue",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tohavedisplayvalue",children:"#"}),(0,r.jsx)(s.code,{children:"toHaveDisplayValue()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toHaveDisplayValue"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" value: string "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" RegExp"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" options"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" exact?"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" boolean;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" normalizer"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" (text"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:") "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" string;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if a ",(0,r.jsx)(s.code,{children:"TextInput"})," has the specified display value. Accepts ",(0,r.jsx)(s.code,{children:"string"})," or ",(0,r.jsx)(s.code,{children:"RegExp"}),", with optional ",(0,r.jsx)(s.a,{href:"/docs/api/queries.html#text-match-options",children:"text match options"})," like ",(0,r.jsx)(s.code,{children:"exact"})," and ",(0,r.jsx)(s.code,{children:"normalizer"}),"."]}),"\n",(0,r.jsxs)(s.h3,{id:"tohaveaccessibilityvalue",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tohaveaccessibilityvalue",children:"#"}),(0,r.jsx)(s.code,{children:"toHaveAccessibilityValue()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toHaveAccessibilityValue"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" value: {"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" min?"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" number;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" max"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" number;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" now"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" number;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" text"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" string "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" RegExp;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsx)(s.p,{children:"Checks if an element has the specified accessible value."}),"\n",(0,r.jsxs)(s.p,{children:["The matcher reads accessibility values from ",(0,r.jsx)(s.code,{children:"aria-valuemin"}),", ",(0,r.jsx)(s.code,{children:"aria-valuemax"}),", ",(0,r.jsx)(s.code,{children:"aria-valuenow"}),", ",(0,r.jsx)(s.code,{children:"aria-valuetext"}),", and ",(0,r.jsx)(s.code,{children:"accessibilityValue"})," props. It only checks the values you specify, so the element can have other accessibility value entries and still match."]}),"\n",(0,r.jsxs)(s.p,{children:["For the ",(0,r.jsx)(s.code,{children:"text"})," entry, you can use a string or ",(0,r.jsx)(s.code,{children:"RegExp"}),"."]}),"\n",(0,r.jsxs)(s.h3,{id:"tobeenabled",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobeenabled",children:"#"}),(0,r.jsx)(s.code,{children:"toBeEnabled()"})," / ",(0,r.jsx)(s.code,{children:"toBeDisabled"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeEnabled"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeDisabled"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element is enabled or disabled from ",(0,r.jsx)(s.code,{children:"aria-disabled"})," or ",(0,r.jsx)(s.code,{children:"accessibilityState.disabled"})," props. An element is disabled if it or any ancestor is disabled."]}),"\n",(0,r.jsx)(l.Pq,{type:"note",title:"Note",children:(0,r.jsxs)(s.p,{children:["\nThese matchers are opposites. Both are available so you can avoid double negations like ",(0,r.jsx)(s.code,{children:"expect(element).not.toBeDisabled()"}),"."]})}),"\n",(0,r.jsxs)(s.h3,{id:"tobeselected",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobeselected",children:"#"}),(0,r.jsx)(s.code,{children:"toBeSelected()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsx)(s.code,{children:(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeSelected"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element is selected from ",(0,r.jsx)(s.code,{children:"aria-selected"})," or ",(0,r.jsx)(s.code,{children:"accessibilityState.selected"})," props."]}),"\n",(0,r.jsxs)(s.h3,{id:"tobechecked",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobechecked",children:"#"}),(0,r.jsx)(s.code,{children:"toBeChecked()"})," / ",(0,r.jsx)(s.code,{children:"toBePartiallyChecked()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeChecked"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBePartiallyChecked"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element is checked or partially checked from ",(0,r.jsx)(s.code,{children:"aria-checked"})," or ",(0,r.jsx)(s.code,{children:"accessibilityState.checked"})," props."]}),"\n",(0,r.jsx)(l.Pq,{type:"note",title:"Note",children:(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"toBeChecked()"})," only works on ",(0,r.jsx)(s.code,{children:"Switch"})," host elements and elements with ",(0,r.jsx)(s.code,{children:"checkbox"}),", ",(0,r.jsx)(s.code,{children:"radio"}),", or ",(0,r.jsx)(s.code,{children:"switch"})," role."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"toBePartiallyChecked()"})," only works on elements with ",(0,r.jsx)(s.code,{children:"checkbox"})," role."]}),"\n"]})}),"\n",(0,r.jsxs)(s.h3,{id:"tobeexpanded",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobeexpanded",children:"#"}),(0,r.jsx)(s.code,{children:"toBeExpanded()"})," / ",(0,r.jsx)(s.code,{children:"toBeCollapsed()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeExpanded"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeCollapsed"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element is expanded or collapsed from ",(0,r.jsx)(s.code,{children:"aria-expanded"})," or ",(0,r.jsx)(s.code,{children:"accessibilityState.expanded"})," props."]}),"\n",(0,r.jsx)(l.Pq,{type:"note",title:"Note",children:(0,r.jsxs)(s.p,{children:["\nThese matchers are opposites for expandable elements (those with explicit ",(0,r.jsx)(s.code,{children:"aria-expanded"})," or ",(0,r.jsx)(s.code,{children:"accessibilityState.expanded"})," props). For non-expandable elements, neither matcher will pass."]})}),"\n",(0,r.jsxs)(s.h3,{id:"tobebusy",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobebusy",children:"#"}),(0,r.jsx)(s.code,{children:"toBeBusy()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsx)(s.code,{children:(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeBusy"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element is busy from ",(0,r.jsx)(s.code,{children:"aria-busy"})," or ",(0,r.jsx)(s.code,{children:"accessibilityState.busy"})," props."]}),"\n",(0,r.jsxs)(s.h2,{id:"checking-element-style",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#checking-element-style",children:"#"}),"Checking element style"]}),"\n",(0,r.jsxs)(s.h3,{id:"tobevisible",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tobevisible",children:"#"}),(0,r.jsx)(s.code,{children:"toBeVisible()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsx)(s.code,{children:(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toBeVisible"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"();"})]})})})}),"\n",(0,r.jsx)(s.p,{children:"Checks if an element is visible."}),"\n",(0,r.jsxs)(s.p,{children:["An element is invisible if it or any ancestor has ",(0,r.jsx)(s.code,{children:"display: none"})," or ",(0,r.jsx)(s.code,{children:"opacity: 0"})," styles, or if it's hidden from accessibility."]}),"\n",(0,r.jsxs)(s.h3,{id:"tohavestyle",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tohavestyle",children:"#"}),(0,r.jsx)(s.code,{children:"toHaveStyle()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toHaveStyle"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" style: StyleProp"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"<"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"Style"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:">"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsx)(s.p,{children:"Checks if an element has specific styles."}),"\n",(0,r.jsxs)(s.h2,{id:"other-matchers",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#other-matchers",children:"#"}),"Other matchers"]}),"\n",(0,r.jsxs)(s.h3,{id:"tohaveaccessiblename",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tohaveaccessiblename",children:"#"}),(0,r.jsx)(s.code,{children:"toHaveAccessibleName()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toHaveAccessibleName"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" name"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" string "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" RegExp"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" options"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" exact?"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" boolean;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" normalizer"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" (text"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:" string"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:") "}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"=>"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" string;"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" }"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element has the specified ",(0,r.jsx)(s.a,{href:"/docs/api/misc/accessibility.html#accessible-name",children:"accessible name"}),". Accepts ",(0,r.jsx)(s.code,{children:"string"})," or ",(0,r.jsx)(s.code,{children:"RegExp"}),", with optional ",(0,r.jsx)(s.a,{href:"/docs/api/queries.html#text-match-options",children:"text match options"})," like ",(0,r.jsx)(s.code,{children:"exact"})," and ",(0,r.jsx)(s.code,{children:"normalizer"}),"."]}),"\n",(0,r.jsxs)(s.p,{children:["See ",(0,r.jsx)(s.a,{href:"/docs/api/misc/accessibility.html#accessible-name",children:"Accessible name"})," for how the accessible name is derived from an element's label props and text content."]}),"\n",(0,r.jsxs)(s.p,{children:["Without a ",(0,r.jsx)(s.code,{children:"name"})," parameter (or with ",(0,r.jsx)(s.code,{children:"undefined"}),"), it only checks whether the element has any accessible name."]}),"\n",(0,r.jsxs)(s.h3,{id:"tohaveprop",children:[(0,r.jsx)(s.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#tohaveprop",children:"#"}),(0,r.jsx)(s.code,{children:"toHaveProp()"})]}),"\n",(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki css-variables",style:{backgroundColor:"var(--shiki-background)",color:"var(--shiki-foreground)"},tabIndex:"0",lang:"ts",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"expect"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"(element)"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:".toHaveProp"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:"("})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" name: string"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" value"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"?:"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:" unknown"}),(0,r.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"var(--shiki-foreground)"},children:")"})})]})})}),"\n",(0,r.jsxs)(s.p,{children:["Checks if an element has a prop. Without a ",(0,r.jsx)(s.code,{children:"value"})," (or with ",(0,r.jsx)(s.code,{children:"undefined"}),"), it only checks if the prop exists. With a ",(0,r.jsx)(s.code,{children:"value"}),", it checks if the prop's value matches."]}),"\n",(0,r.jsx)(l.Pq,{type:"note",title:"Note",children:(0,r.jsx)(s.p,{children:"\nUse this matcher as a last resort when other matchers don't fit your needs."})})]})}function a(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(o,{...e})}):o(e)}a.__RSPRESS_PAGE_META={},a.__RSPRESS_PAGE_META["14.x%2Fdocs%2Fapi%2Fjest-matchers.mdx"]={toc:[{id:"setup",text:"Setup",depth:2},{id:"checking-element-existence",text:"Checking element existence",depth:2},{id:"tobeonthescreen",text:"`toBeOnTheScreen()`",depth:3},{id:"element-content",text:"Element Content",depth:2},{id:"tohavetextcontent",text:"`toHaveTextContent()`",depth:3},{id:"tocontainelement",text:"`toContainElement()`",depth:3},{id:"tobeemptyelement",text:"`toBeEmptyElement()`",depth:3},{id:"checking-element-state",text:"Checking element state",depth:2},{id:"tohavedisplayvalue",text:"`toHaveDisplayValue()`",depth:3},{id:"tohaveaccessibilityvalue",text:"`toHaveAccessibilityValue()`",depth:3},{id:"tobeenabled",text:"`toBeEnabled()` / `toBeDisabled`",depth:3},{id:"tobeselected",text:"`toBeSelected()`",depth:3},{id:"tobechecked",text:"`toBeChecked()` / `toBePartiallyChecked()`",depth:3},{id:"tobeexpanded",text:"`toBeExpanded()` / `toBeCollapsed()`",depth:3},{id:"tobebusy",text:"`toBeBusy()`",depth:3},{id:"checking-element-style",text:"Checking element style",depth:2},{id:"tobevisible",text:"`toBeVisible()`",depth:3},{id:"tohavestyle",text:"`toHaveStyle()`",depth:3},{id:"other-matchers",text:"Other matchers",depth:2},{id:"tohaveaccessiblename",text:"`toHaveAccessibleName()`",depth:3},{id:"tohaveprop",text:"`toHaveProp()`",depth:3}],title:"Jest matchers",headingTitle:"Jest matchers",frontmatter:{}}}}]);