Files
github-actions[bot] 3d4e06fb76 deploy: a7fa320588
2026-06-05 14:28:20 +00:00

1 line
4.9 KiB
JavaScript

"use strict";(self.rspackChunkwebsite=self.rspackChunkwebsite||[]).push([["8632"],{9099(e,t,n){n.r(t),n.d(t,{default:()=>a});var s=n(4848),r=n(8453);function i(e){let t={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",p:"p",ul:"ul",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.h1,{id:"faq",children:[(0,s.jsx)(t.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#faq",children:"#"}),"FAQ"]}),"\n",(0,s.jsxs)(t.h2,{id:"can-i-test-the-native-features-of-react-native-apps",children:[(0,s.jsx)(t.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#can-i-test-the-native-features-of-react-native-apps",children:"#"}),"Can I test the native features of React Native apps?"]}),"\n",(0,s.jsx)(t.p,{children:"Short answer: no."}),"\n",(0,s.jsx)(t.p,{children:"React Native Testing Library does not provide an entire React Native runtime since that would require running on a physical device\nor iOS simulator/Android emulator to provision the underlying OS and platform APIs."}),"\n",(0,s.jsxs)(t.p,{children:["Instead of using React Native renderer, it simulates only the JavaScript part of its runtime\nusing ",(0,s.jsx)(t.a,{href:"https://github.com/mdjastrzebski/test-renderer",rel:"noopener noreferrer",target:"_blank",children:"Test Renderer"})," while providing queries\nand event APIs (",(0,s.jsx)(t.a,{href:"/docs/api/events/user-event.html",children:"User Event"}),", ",(0,s.jsx)(t.a,{href:"/docs/api/events/fire-event.html",children:"Fire Event"}),") that mimicking certain behaviors from the actual runtime."]}),"\n",(0,s.jsxs)(t.p,{children:["You can learn more about our testing environment ",(0,s.jsx)(t.a,{href:"/docs/advanced/testing-env.html",children:"here"}),"."]}),"\n",(0,s.jsx)(t.p,{children:"This approach has benefits and limitations:"}),"\n",(0,s.jsx)(t.p,{children:"Benefits:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:"Tests most of the logic of regular React Native apps"}),"\n",(0,s.jsx)(t.li,{children:"Runs tests on any OS supported by Jest or other test runners, e.g., on CI"}),"\n",(0,s.jsx)(t.li,{children:"Uses fewer resources than full runtime simulation"}),"\n",(0,s.jsx)(t.li,{children:"Works with Jest fake timers"}),"\n"]}),"\n",(0,s.jsx)(t.p,{children:"Limitations:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsx)(t.li,{children:"Cannot test native features"}),"\n",(0,s.jsx)(t.li,{children:"May not perfectly simulate certain JavaScript features, but we're working on it"}),"\n"]}),"\n",(0,s.jsxs)(t.p,{children:["The ",(0,s.jsx)(t.a,{href:"/docs/api/events/user-event.html",children:"User Event interactions"})," solve some simulation issues by handling events more realistically than the basic ",(0,s.jsx)(t.a,{href:"/docs/api/events/fire-event.html",children:"Fire Event API"}),"."]}),"\n",(0,s.jsxs)(t.h2,{id:"should-i-usemigrate-to-screen-queries",children:[(0,s.jsx)(t.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#should-i-usemigrate-to-screen-queries",children:"#"}),"Should I use/migrate to ",(0,s.jsx)(t.code,{children:"screen"})," queries?"]}),"\n",(0,s.jsxs)(t.p,{children:["There is no need to migrate existing test code to use ",(0,s.jsx)(t.code,{children:"screen"}),"-bases queries. You can still use\nqueries and other functions returned by ",(0,s.jsx)(t.code,{children:"render"}),". The ",(0,s.jsx)(t.code,{children:"screen"})," object captures the latest ",(0,s.jsx)(t.code,{children:"render"})," result."]}),"\n",(0,s.jsxs)(t.p,{children:["For new code, use ",(0,s.jsx)(t.code,{children:"screen"}),". ",(0,s.jsx)(t.a,{href:"https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen",rel:"noopener noreferrer",target:"_blank",children:"This article"})," by Kent C. Dodds explains why."]}),"\n",(0,s.jsxs)(t.h2,{id:"should-i-usemigrate-to-user-event-interactions",children:[(0,s.jsx)(t.a,{className:"rp-header-anchor","aria-hidden":"true",href:"#should-i-usemigrate-to-user-event-interactions",children:"#"}),"Should I use/migrate to User Event interactions?"]}),"\n",(0,s.jsxs)(t.p,{children:["Migrate existing tests to use the ",(0,s.jsx)(t.a,{href:"/docs/api/events/user-event.html",children:"User Event interactions"}),", which handle events more realistically than the basic ",(0,s.jsx)(t.a,{href:"/docs/api/events/fire-event.html",children:"Fire Event API"}),". This provides more confidence in your code quality."]})]})}function a(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(i,{...e})}):i(e)}a.__RSPRESS_PAGE_META={},a.__RSPRESS_PAGE_META["14.x%2Fdocs%2Fguides%2Ffaq.mdx"]={toc:[{id:"can-i-test-the-native-features-of-react-native-apps",text:"Can I test the native features of React Native apps?",depth:2},{id:"should-i-usemigrate-to-screen-queries",text:"Should I use/migrate to `screen` queries?",depth:2},{id:"should-i-usemigrate-to-user-event-interactions",text:"Should I use/migrate to User Event interactions?",depth:2}],title:"FAQ",headingTitle:"FAQ",frontmatter:{}}}}]);