├── .all-contributorsrc ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── Bug_Report.md │ ├── Feature_Request.md │ └── Question.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmrc ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── babel.config.js ├── cleanup-after-each.js ├── examples ├── __tests__ │ ├── input-event.js │ ├── react-context.js │ ├── react-intl.js │ ├── react-navigation.js │ ├── react-redux.js │ ├── update-props.js │ └── use-hooks.js └── react-context.js ├── jest-preset.js ├── jest.config.js ├── other ├── cheat-sheet.pdf └── whale.png ├── package.json ├── pure.js ├── src ├── __tests__ │ ├── __snapshots__ │ │ ├── fetch.js.snap │ │ ├── misc.js.snap │ │ └── render.js.snap │ ├── act.js │ ├── bugs.js │ ├── debug.js │ ├── end-to-end.js │ ├── events.js │ ├── fetch.js │ ├── forms.js │ ├── misc.js │ ├── new-act.js │ ├── no-act.js │ ├── old-act.js │ ├── render.js │ ├── rerender.js │ └── stopwatch.js ├── act-compat.js ├── cleanup-async.js ├── index.js ├── lib │ ├── __tests__ │ │ ├── __snapshots__ │ │ │ └── to-json.js.snap │ │ ├── config.js │ │ ├── get-by-errors.js │ │ ├── helpers.js │ │ ├── matches.js │ │ ├── misc.js │ │ ├── pretty-print.js │ │ ├── queries.find.js │ │ ├── query-helpers.js │ │ ├── text-matchers.js │ │ ├── to-json.js │ │ ├── wait-for-element-to-be-removed.fake-timers.js │ │ ├── wait-for-element-to-be-removed.js │ │ ├── wait-for-element.js │ │ ├── wait.js │ │ └── within.js │ ├── config.js │ ├── events.js │ ├── get-node-text.js │ ├── get-queries-for-element.js │ ├── helpers.js │ ├── index.js │ ├── matches.js │ ├── pretty-print.js │ ├── queries │ │ ├── all-utils.js │ │ ├── display-value.js │ │ ├── hint-text.js │ │ ├── index.js │ │ ├── label-text.js │ │ ├── placeholder-text.js │ │ ├── role.js │ │ ├── test-id.js │ │ ├── text.js │ │ └── title.js │ ├── query-helpers.js │ ├── to-json.js │ ├── wait-for-element-to-be-removed.js │ ├── wait-for-element.js │ └── wait.js └── preset │ ├── configure.js │ ├── mock-component.js │ ├── mock-modules.js │ ├── mock-native-methods.js │ ├── mock-refresh-control.js │ ├── mock-scroll-view.js │ ├── serializer.js │ └── setup.js └── typings ├── config.d.ts ├── events.d.ts ├── get-node-text.d.ts ├── get-queries-for-element.d.ts ├── index.d.ts ├── matches.d.ts ├── pretty-print.d.ts ├── queries.d.ts ├── query-helpers.d.ts ├── to-json.d.ts ├── wait-for-element-to-be-removed.d.ts ├── wait-for-element.d.ts └── wait.d.ts /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "native-testing-library", 3 | "projectOwner": "testing-library", 4 | "repoType": "github", 5 | "files": [ 6 | "README.md" 7 | ], 8 | "imageSize": 100, 9 | "commit": true, 10 | "commitConvention": "angular", 11 | "contributors": [ 12 | { 13 | "login": "bcarroll22", 14 | "name": "Brandon Carroll", 15 | "avatar_url": "https://avatars2.githubusercontent.com/u/11020406?v=4", 16 | "profile": "https://github.com/bcarroll22", 17 | "contributions": [ 18 | "code", 19 | "doc", 20 | "infra", 21 | "test" 22 | ] 23 | }, 24 | { 25 | "login": "TAGraves", 26 | "name": "Tommy Graves", 27 | "avatar_url": "https://avatars1.githubusercontent.com/u/2263711?v=4", 28 | "profile": "http://tagraves.com", 29 | "contributions": [ 30 | "ideas", 31 | "maintenance", 32 | "review" 33 | ] 34 | }, 35 | { 36 | "login": "kentcdodds", 37 | "name": "Kent C. Dodds", 38 | "avatar_url": "https://avatars.githubusercontent.com/u/1500684?v=3", 39 | "profile": "https://kentcdodds.com", 40 | "contributions": [ 41 | "ideas" 42 | ] 43 | }, 44 | { 45 | "login": "sz-piotr", 46 | "name": "Piotr Szlachciak", 47 | "avatar_url": "https://avatars2.githubusercontent.com/u/17070569?v=4", 48 | "profile": "https://github.com/sz-piotr", 49 | "contributions": [ 50 | "code" 51 | ] 52 | }, 53 | { 54 | "login": "mcgloneleviROOT", 55 | "name": "mcgloneleviROOT", 56 | "avatar_url": "https://avatars3.githubusercontent.com/u/48258981?v=4", 57 | "profile": "https://github.com/mcgloneleviROOT", 58 | "contributions": [ 59 | "bug", 60 | "code" 61 | ] 62 | }, 63 | { 64 | "login": "wolverineks", 65 | "name": "Kevin Sullivan", 66 | "avatar_url": "https://avatars2.githubusercontent.com/u/8462274?v=4", 67 | "profile": "http://exercism.io/profiles/wolverineks/619ce225090a43cb891d2edcbbf50401", 68 | "contributions": [ 69 | "doc" 70 | ] 71 | }, 72 | { 73 | "login": "elyalvarado", 74 | "name": "Ely Alvarado", 75 | "avatar_url": "https://avatars1.githubusercontent.com/u/545352?v=4", 76 | "profile": "https://github.com/elyalvarado", 77 | "contributions": [ 78 | "code" 79 | ] 80 | }, 81 | { 82 | "login": "lewie9021", 83 | "name": "Lewis Barnes", 84 | "avatar_url": "https://avatars3.githubusercontent.com/u/4729411?v=4", 85 | "profile": "https://github.com/lewie9021", 86 | "contributions": [ 87 | "code", 88 | "question" 89 | ] 90 | }, 91 | { 92 | "login": "mAAdhaTTah", 93 | "name": "James DiGioia", 94 | "avatar_url": "https://avatars0.githubusercontent.com/u/4371429?v=4", 95 | "profile": "http://jamesdigioia.com", 96 | "contributions": [ 97 | "code" 98 | ] 99 | }, 100 | { 101 | "login": "manakuro", 102 | "name": "mana", 103 | "avatar_url": "https://avatars1.githubusercontent.com/u/11571318?v=4", 104 | "profile": "https://manatoworks.me", 105 | "contributions": [ 106 | "code" 107 | ] 108 | }, 109 | { 110 | "login": "mateusz1913", 111 | "name": "Mateusz Mędrek", 112 | "avatar_url": "https://avatars2.githubusercontent.com/u/25980166?v=4", 113 | "profile": "https://github.com/mateusz1913", 114 | "contributions": [ 115 | "code" 116 | ] 117 | }, 118 | { 119 | "login": "smakosh", 120 | "name": "Ismail Ghallou ", 121 | "avatar_url": "https://avatars0.githubusercontent.com/u/20082141?v=4", 122 | "profile": "https://smakosh.com", 123 | "contributions": [ 124 | "doc" 125 | ] 126 | }, 127 | { 128 | "login": "jeffreyffs", 129 | "name": "jeffreyffs", 130 | "avatar_url": "https://avatars1.githubusercontent.com/u/1441462?v=4", 131 | "profile": "https://github.com/jeffreyffs", 132 | "contributions": [ 133 | "code" 134 | ] 135 | }, 136 | { 137 | "login": "SophieAu", 138 | "name": "Sophie Au", 139 | "avatar_url": "https://avatars2.githubusercontent.com/u/11145039?v=4", 140 | "profile": "https://www.sophieau.com/", 141 | "contributions": [ 142 | "code" 143 | ] 144 | }, 145 | { 146 | "login": "ajsmth", 147 | "name": "andy", 148 | "avatar_url": "https://avatars2.githubusercontent.com/u/40680668?v=4", 149 | "profile": "http://ajsmth.com", 150 | "contributions": [ 151 | "code", 152 | "doc" 153 | ] 154 | }, 155 | { 156 | "login": "aiham", 157 | "name": "Aiham", 158 | "avatar_url": "https://avatars2.githubusercontent.com/u/609164?v=4", 159 | "profile": "https://github.com/aiham", 160 | "contributions": [ 161 | "code" 162 | ] 163 | }, 164 | { 165 | "login": "sibelius", 166 | "name": "Sibelius Seraphini", 167 | "avatar_url": "https://avatars3.githubusercontent.com/u/2005841?v=4", 168 | "profile": "https://twitter.com/sseraphini", 169 | "contributions": [ 170 | "code" 171 | ] 172 | }, 173 | { 174 | "login": "AEgan", 175 | "name": "Alex Egan", 176 | "avatar_url": "https://avatars0.githubusercontent.com/u/3501927?v=4", 177 | "profile": "https://github.com/AEgan", 178 | "contributions": [ 179 | "code" 180 | ] 181 | }, 182 | { 183 | "login": "daveols", 184 | "name": "Dave Olsen", 185 | "avatar_url": "https://avatars3.githubusercontent.com/u/10344370?v=4", 186 | "profile": "http://daveolsen.com.au", 187 | "contributions": [ 188 | "code", 189 | "test", 190 | "doc" 191 | ] 192 | } 193 | ], 194 | "contributorsPerLine": 7, 195 | "repoHost": "https://github.com", 196 | "skipCi": true 197 | } 198 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: testing-library 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Bug_Report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report 3 | about: I think something is broken 😡 4 | --- 5 | 6 | 14 | 15 | - `react-native` or `expo`: 16 | - `native-testing-library` version: 17 | - `jest-preset`: 18 | - `react-native` version: 19 | - `node` version: 20 | 21 | ### Relevant code or config: 22 | 23 | ```js 24 | const your = code => 'here'; 25 | ``` 26 | 27 | ### What you did: 28 | 29 | 30 | 31 | ### What happened: 32 | 33 | 34 | 35 | ### Reproduction: 36 | 37 | 38 | 39 | ### Problem description: 40 | 41 | 42 | 43 | ### Suggested solution: 44 | 45 | 46 | 47 | ### Can you help us fix this issue by submitting a pull request? 48 | 49 | 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_Request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 💡 Feature Request 3 | about: I think something could be better 🤔 4 | --- 5 | 6 | 15 | 16 | **Describe the feature you'd like:** 17 | 18 | 19 | 20 | **Suggested implementation:** 21 | 22 | 23 | 24 | **Describe alternatives you've considered:** 25 | 26 | 27 | 28 | **Teachability, Documentation, Adoption, Migration Strategy:** 29 | 30 | 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ❓ Support Question 3 | about: I think I don't understand how to do something 🤨 4 | --- 5 | 6 | 7 | 8 | Issues on GitHub are intended to be related to problems and feature requests so we ask you not use 9 | issues to ask for support. 10 | 11 | Remember that this library is almost entirely the same as `react-testing-library` so you're likely 12 | to get some great advice by searching for how to do something with it. 13 | 14 | --- 15 | 16 | ## ❓ React Testing Library Resources 17 | 18 | - Discord https://discord.gg/c6JN9fM 19 | - Stack Overflow https://stackoverflow.com/questions/tagged/react-testing-library 20 | 21 | ## ❓ Native Testing Library Resources 22 | 23 | - Stack Overflow https://stackoverflow.com/questions/tagged/native-testing-library 24 | 25 | **ISSUES WHICH ARE QUESTIONS WILL BE CLOSED** 26 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | **What**: 12 | 13 | 14 | 15 | **Why**: 16 | 17 | 18 | 19 | **How**: 20 | 21 | 22 | 23 | **Checklist**: 24 | 25 | 26 | 27 | 28 | 29 | - [ ] Documentation added to the 30 | [docs site](https://github.com/bcarroll22/native-testing-library-docs) 31 | - [ ] Typescript definitions updated 32 | - [ ] Tests 33 | - [ ] Ready to be merged 34 | 35 | 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | dist/ 4 | .idea/ 5 | .DS_Store 6 | 7 | yarn-error.log 8 | 9 | package-lock.json 10 | yarn.lock 11 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | registry=http://registry.npmjs.org/ 2 | package-lock=false 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '8' 5 | - '9' 6 | - '10' 7 | - '11' 8 | cache: 9 | npm: true 10 | directories: 11 | - coverage 12 | notifications: 13 | email: false 14 | install: npm i && npm i -g codecov 15 | script: npm run test:coverage && codecov 16 | jobs: 17 | include: 18 | - stage: release 19 | if: branch = master AND type != pull_request 20 | node_js: '10' 21 | script: npm run semantic-release 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | The changelog is automatically updated using 4 | [semantic-release](https://github.com/semantic-release/semantic-release). You 5 | can see it on the [releases page](../../releases). 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at brandonvcarroll@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2019 Brandon Carroll 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ Deprecation notice ⚠️ 2 | 3 | This repository has been deprecated in favor of https://github.com/callstack/react-native-testing-library and the `@testing-library/react-native` npm package will from now on (since v7.0) will be sourced from there. Please consult the [migration guide](https://callstack.github.io/react-native-testing-library/docs/migration-v7/#guide-for-testing-libraryreact-native-users). 4 | 5 | 6 |
7 |

Native Testing Library

8 | 9 | 10 | whale 16 | 17 | 18 |

Simple and complete React Native testing utilities that encourage good testing practices.

19 | 20 | [**Read The Docs**](https://native-testing-library.com/docs/intro) | 21 | [Edit the docs](https://github.com/testing-library/native-testing-library-docs) 22 |
23 | 24 |
25 | 26 | [![Build Status](https://travis-ci.org/testing-library/native-testing-library.svg?branch=master)](https://travis-ci.org/testing-library/native-testing-library) 27 | [![Code Coverage](https://img.shields.io/codecov/c/github/testing-library/native-testing-library.svg?style=flat-square)](https://codecov.io/github/testing-library/native-testing-library) 28 | [![version](https://img.shields.io/npm/v/@testing-library/react-native.svg?style=flat-square)](https://www.npmjs.com/package/@testing-library/react-native) 29 | [![downloads](https://img.shields.io/npm/dm/@testing-library/react-native.svg?style=flat-square)](http://www.npmtrends.com/@testing-library/react-native) 30 | [![MIT License](https://img.shields.io/npm/l/@testing-library/react-native.svg?style=flat-square)](https://github.com/testing-library/native-testing-library/blob/master/LICENSE) 31 | 32 | [![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors) 33 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 34 | [![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/testing-library/native-testing-library/blob/master/CODE_OF_CONDUCT.md) 35 | [![Discord](https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square)](https://discord.gg/c6JN9fM) 36 | 37 | [![Watch on GitHub](https://img.shields.io/github/watchers/testing-library/native-testing-library.svg?style=social)](https://github.com/testing-library/native-testing-library/watchers) 38 | [![Star on GitHub](https://img.shields.io/github/stars/testing-library/native-testing-library.svg?style=social)](https://github.com/testing-library/native-testing-library/stargazers) 39 | 40 | 41 | 42 | 43 | ## Table of Contents 44 | 45 | - [The problem](#the-problem) 46 | - [This solution](#this-solution) 47 | - [Example](#example) 48 | - [Installation](#installation) 49 | - [Hooks](#hooks) 50 | - [Other Solutions](#other-solutions) 51 | - [Guiding Principles](#guiding-principles) 52 | - [Inspiration](#inspiration) 53 | - [Contributors](#contributors) 54 | - [Docs](#docs) 55 | 56 | 57 | 58 | ## The problem 59 | 60 | You want to write maintainable tests for your React Native application. You love Kent Dodds' testing 61 | library, and you want to be able to write maintainable tests for your React Native application. You 62 | don't want to use a library that renders components to a fake DOM, and you've had a hard time 63 | finding what you need to write tests using that philosophy in React Native. 64 | 65 | ## This solution 66 | 67 | `native-testing-library` is an implementation of the well-known testing-library API that works for 68 | React Native. The primary goal is to mimic the testing library API as closely as possible while 69 | still accounting for the differences in the platforms. 70 | 71 | ## Example 72 | 73 | ```javascript 74 | import React from 'react'; 75 | import { Button, Text, TextInput, View } from 'react-native'; 76 | import { fireEvent, render, wait } from '@testing-library/react-native'; 77 | 78 | function Example() { 79 | const [name, setUser] = React.useState(''); 80 | const [show, setShow] = React.useState(false); 81 | 82 | return ( 83 | 84 | 85 |