├── .all-contributorsrc ├── .dockerignore ├── .gitignore ├── .prettierrc ├── Dockerfile ├── README.md ├── docker-compose.yml ├── docs ├── api-act.md ├── api-async.md ├── api-events.md ├── api-helpers.md ├── api-main.md ├── api-queries.md ├── api-test-instance.md ├── cheat-sheet.md ├── ecosystem-jest-native.md ├── example-context.md ├── example-input-event.md ├── example-intl.md ├── example-navigation.md ├── example-redux.md ├── example-update-props.md ├── example.md ├── guide-disappearance.md ├── guide-queries.md ├── guiding-principles.md ├── install.md ├── intro.md └── setup.md └── website ├── README.md ├── blog ├── 2016-03-11-blog-post.md ├── 2017-04-10-blog-post-two.md ├── 2017-09-25-testing-rss.md ├── 2017-09-26-adding-rss.md └── 2017-10-24-new-version-1.0.0.md ├── core └── Footer.js ├── package.json ├── pages └── en │ ├── help.js │ ├── index.js │ ├── users.js │ └── versions.js ├── sidebars.json ├── siteConfig.js ├── static ├── css │ ├── code-block-buttons.css │ └── custom.css ├── img │ ├── favicon │ │ └── favicon.ico │ ├── whale-128x128.png │ ├── whale-32x32.png │ └── whale-64x64.png └── js │ └── code-block-buttons.js ├── versioned_docs ├── version-2.0.0 │ ├── api-act.md │ ├── api-async.md │ ├── api-events.md │ ├── api-helpers.md │ ├── api-queries.md │ ├── api-render-hook.md │ ├── api-render.md │ ├── cheat-sheet.md │ ├── ecosystem-jest-native.md │ ├── example-context.md │ ├── example-input-event.md │ ├── example-intl.md │ ├── example-navigation.md │ ├── example-redux.md │ ├── example-update-props.md │ ├── example.md │ ├── guide-disappearance.md │ ├── guide-queries.md │ ├── guiding-principles.md │ ├── hook-example-async.md │ ├── hook-example-custom.md │ ├── hook-example-error.md │ ├── hook-example-test.md │ ├── hook-example-use-context.md │ ├── hook-example-use-effect.md │ ├── hook-example-use-memo.md │ ├── hook-example-use-reducer.md │ ├── hook-example-use-ref.md │ ├── hook-example-use-state.md │ ├── install.md │ ├── intro.md │ └── setup.md ├── version-3.0.0 │ ├── api-act.md │ ├── api-async.md │ ├── api-events.md │ ├── api-helpers.md │ ├── api-main.md │ ├── api-queries.md │ ├── api-test-instance.md │ ├── ecosystem-jest-native.md │ ├── example-input-event.md │ ├── example-update-props.md │ ├── guide-disappearance.md │ ├── guide-queries.md │ ├── install.md │ ├── intro.md │ └── setup.md └── version-4.0.0 │ ├── api-act.md │ ├── api-events.md │ ├── api-helpers.md │ ├── api-main.md │ ├── api-queries.md │ ├── cheat-sheet.md │ ├── ecosystem-jest-native.md │ ├── example-context.md │ ├── example-input-event.md │ ├── example-intl.md │ ├── example-navigation.md │ ├── example-redux.md │ ├── example-update-props.md │ ├── example.md │ ├── guide-disappearance.md │ ├── guiding-principles.md │ ├── install.md │ ├── intro.md │ └── setup.md ├── versioned_sidebars ├── version-2.0.0-sidebars.json └── version-3.0.0-sidebars.json └── versions.json /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "native-testing-library-docs", 3 | "projectOwner": "testing-library", 4 | "repoType": "github", 5 | "repoHost": "https://github.com", 6 | "files": [ 7 | "README.md" 8 | ], 9 | "imageSize": 100, 10 | "commit": true, 11 | "commitConvention": "angular", 12 | "contributors": [ 13 | { 14 | "login": "bcarroll22", 15 | "name": "Brandon Carroll", 16 | "avatar_url": "https://avatars2.githubusercontent.com/u/11020406?v=4", 17 | "profile": "https://github.com/bcarroll22", 18 | "contributions": [ 19 | "code", 20 | "content", 21 | "doc", 22 | "design" 23 | ] 24 | }, 25 | { 26 | "login": "jmporchet", 27 | "name": "Jean-Marie Porchet", 28 | "avatar_url": "https://avatars3.githubusercontent.com/u/3099008?v=4", 29 | "profile": "http://www.jmporchet.ch", 30 | "contributions": [ 31 | "doc" 32 | ] 33 | }, 34 | { 35 | "login": "SantiMA10", 36 | "name": "Santi", 37 | "avatar_url": "https://avatars2.githubusercontent.com/u/7255298?v=4", 38 | "profile": "http://santiagomartin.dev", 39 | "contributions": [ 40 | "doc" 41 | ] 42 | }, 43 | { 44 | "login": "elyalvarado", 45 | "name": "Ely Alvarado", 46 | "avatar_url": "https://avatars1.githubusercontent.com/u/545352?v=4", 47 | "profile": "https://github.com/elyalvarado", 48 | "contributions": [ 49 | "doc" 50 | ] 51 | }, 52 | { 53 | "login": "neiker", 54 | "name": "Javier Alvarez", 55 | "avatar_url": "https://avatars0.githubusercontent.com/u/688444?v=4", 56 | "profile": "https://twitter.com/neiker", 57 | "contributions": [ 58 | "doc" 59 | ] 60 | }, 61 | { 62 | "login": "mattfwood", 63 | "name": "Matt Wood", 64 | "avatar_url": "https://avatars1.githubusercontent.com/u/22530815?v=4", 65 | "profile": "https://mattwood.tech/", 66 | "contributions": [ 67 | "doc" 68 | ] 69 | }, 70 | { 71 | "login": "jeremyadavis", 72 | "name": "Jeremy Davis", 73 | "avatar_url": "https://avatars3.githubusercontent.com/u/297572?v=4", 74 | "profile": "http://www.twitter.com/jeremydavis", 75 | "contributions": [ 76 | "doc" 77 | ] 78 | }, 79 | { 80 | "login": "MoeSauber", 81 | "name": "MoeSauber", 82 | "avatar_url": "https://avatars0.githubusercontent.com/u/53796298?v=4", 83 | "profile": "https://github.com/MoeSauber", 84 | "contributions": [ 85 | "doc" 86 | ] 87 | }, 88 | { 89 | "login": "hansjhoffman", 90 | "name": "Hans Hoffman", 91 | "avatar_url": "https://avatars2.githubusercontent.com/u/9221098?v=4", 92 | "profile": "https://github.com/hansjhoffman", 93 | "contributions": [ 94 | "doc" 95 | ] 96 | }, 97 | { 98 | "login": "cloud-walker", 99 | "name": "Luca Barone", 100 | "avatar_url": "https://avatars3.githubusercontent.com/u/1144075?v=4", 101 | "profile": "https://github.com/cloud-walker", 102 | "contributions": [ 103 | "doc" 104 | ] 105 | }, 106 | { 107 | "login": "lhache", 108 | "name": "Louis H", 109 | "avatar_url": "https://avatars3.githubusercontent.com/u/4593884?v=4", 110 | "profile": "https://github.com/lhache", 111 | "contributions": [ 112 | "doc" 113 | ] 114 | } 115 | ], 116 | "contributorsPerLine": 7, 117 | "skipCi": true 118 | } 119 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | */node_modules 2 | *.log 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | node_modules 4 | 5 | lib/core/metadata.js 6 | lib/core/MetadataBlog.js 7 | 8 | website/translated_docs 9 | website/build/ 10 | website/yarn.lock 11 | website/node_modules 12 | website/i18n/* 13 | 14 | .idea/* 15 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "proseWrap": "always", 4 | "singleQuote": true, 5 | "tabWidth": 2, 6 | "trailingComma": "all" 7 | } 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8.11.4 2 | 3 | WORKDIR /app/website 4 | 5 | EXPOSE 3000 35729 6 | COPY website /app/docs 7 | COPY ./website /app/website 8 | RUN yarn install 9 | 10 | CMD ["yarn", "start"] 11 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | docusaurus: 5 | build: . 6 | ports: 7 | - 3000:3000 8 | - 35729:35729 9 | volumes: 10 | - ./docs:/app/docs 11 | - ./website/blog:/app/website/blog 12 | - ./website/core:/app/website/core 13 | - ./website/i18n:/app/website/i18n 14 | - ./website/pages:/app/website/pages 15 | - ./website/static:/app/website/static 16 | - ./website/sidebars.json:/app/website/sidebars.json 17 | - ./website/siteConfig.js:/app/website/siteConfig.js 18 | working_dir: /app/website 19 | -------------------------------------------------------------------------------- /docs/api-act.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: api-act 3 | title: Act 4 | sidebar_label: Act 5 | --- 6 | 7 | ## `act` 8 | 9 | This is a light wrapper around the 10 | [`react-test-renderer` `act` function](https://reactjs.org/docs/test-renderer.html). All it does is 11 | forward all arguments to the act function if your version of react supports `act`. 12 | -------------------------------------------------------------------------------- /docs/api-async.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: api-async 3 | title: Async Utilities 4 | sidebar_label: Async Utilities 5 | --- 6 | 7 | Several utilities are provided for dealing with asynchronous code. These can be useful to wait for 8 | an element to appear or disappear in response to an action. (See the 9 | [guide to testing disappearance](guide-disappearance.md).) 10 | 11 | ## `wait` 12 | 13 | ```typescript 14 | function wait( 15 | callback?: () => void, 16 | options?: { 17 | timeout?: number; 18 | interval?: number; 19 | }, 20 | ): Promise; 21 | ``` 22 | 23 | When in need to wait for non-deterministic periods of time you can use `wait`, to wait for your 24 | expectations to pass. The `wait` function is a small wrapper around the 25 | [`wait-for-expect`](https://github.com/TheBrainFamily/wait-for-expect) module. Here's a simple 26 | example: 27 | 28 | ```javascript 29 | await wait(() => getByLabelText('username')); 30 | getByLabelText('username').value = 'chucknorris'; 31 | ``` 32 | 33 | This can be useful if you have a unit test that mocks API calls and you need to wait for your mock 34 | promises to all resolve. 35 | 36 | The default `callback` is a no-op function (used like `await wait()`). This can be helpful if you 37 | only need to wait for one tick of the event loop (in the case of mocked API calls with promises that 38 | resolve immediately). 39 | 40 | The default `timeout` is `4500ms` which will keep you under 41 | [Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout). 42 | 43 | The default `interval` is `50ms`. However it will run your callback immediately on the next tick of 44 | the event loop (in a `setTimeout`) before starting the intervals. 45 | 46 | ## `waitForElement` 47 | 48 | ```typescript 49 | function waitForElement( 50 | callback: () => T, 51 | options?: { 52 | timeout?: number; 53 | interval?: number; 54 | }, 55 | ): Promise; 56 | ``` 57 | 58 | When you need to wait for elements to appear, you can use `waitForElement`. The `waitForElement` 59 | function is a similar to `wait`, but is specifically intended to wait for an element to appear. 60 | Additionally, the result is returned for you to use. 61 | 62 | Here's a simple example: 63 | 64 | ```javascript 65 | const usernameElement = await waitForElement(() => getByLabelText('username')); 66 | expect(usernameElement).toHaveTextContent('chucknorris'); 67 | ``` 68 | 69 | You can also wait for multiple elements at once: 70 | 71 | ```javascript 72 | const [usernameElement, passwordElement] = await waitForElement(() => [ 73 | getByLabelText('username'), 74 | getByLabelText('password'), 75 | ]); 76 | ``` 77 | 78 | The default `timeout` is `4500ms` which will keep you under 79 | [Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout). 80 | 81 | The default `interval` is `50ms`. However it will run your callback immediately on the next tick of 82 | the event loop (in a `setTimeout`) before starting the intervals. 83 | 84 | ## `waitForElementToBeRemoved` 85 | 86 | ```typescript 87 | function waitForElementToBeRemoved( 88 | callback: () => T, 89 | options?: { 90 | timeout?: number; 91 | interval?: number; 92 | }, 93 | ): Promise; 94 | ``` 95 | 96 | When you need to wait for elements to be removed, or you can use `waitForElementToBeRemoved`. The 97 | `waitForElementToBeRemoved` function is a similar to `wait`, but is a helper specifically intended 98 | to wait for an element to be removed from the tree. Similarly to `waitForElement` the result of the 99 | callback is returned as a Promise, but in most cases you won't need it. 100 | 101 | Here's a simple example: 102 | 103 | ```javascript 104 | await waitForElementToBeRemoved(() => queryAllByLabelText('list-item')); 105 | ``` 106 | 107 | The default `timeout` is `4500ms` which will keep you under 108 | [Jest's default timeout of `5000ms`](https://facebook.github.io/jest/docs/en/jest-object.html#jestsettimeouttimeout). 109 | 110 | The default `interval` is `50ms`. However it will run your callback immediately on the next tick of 111 | the event loop (in a `setTimeout`) before starting the intervals. 112 | -------------------------------------------------------------------------------- /docs/api-events.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: api-events 3 | title: Firing Events 4 | sidebar_label: Firing Events 5 | --- 6 | 7 | ## Basic example 8 | 9 | ```javascript 10 | import { fireEvent, NativeTestEvent, render } from '@testing-library/react-native'; 11 | 12 | const { getByText } = render(