Skip to content
This repository was archived by the owner on Aug 1, 2020. It is now read-only.

Commit 0fd36ca

Browse files
committed
docs: tag version 3 docs
1 parent 610a889 commit 0fd36ca

19 files changed

+1320
-63
lines changed

docs/api-render.md renamed to docs/api-main.md

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
id: api-render
3-
title: Render
4-
sidebar_label: Render
2+
id: api-main
3+
title: Main
4+
sidebar_label: Main
55
---
66

77
## `render`
@@ -15,7 +15,7 @@ function render(
1515
): RenderResult;
1616
```
1717

18-
Create a `ReactTestRenderer Instance`.
18+
Create a `NativeTestInstance`.
1919

2020
```jsx
2121
import { render } from 'native-testing-library';
@@ -24,13 +24,17 @@ render(<View />);
2424
```
2525

2626
```javascript
27-
import { render } from 'native-testing-library';
27+
import { render, toJSON } from 'native-testing-library';
2828

2929
test('renders a message', () => {
3030
const { container, getByText } = render(<Text>Hello, World!</Text>);
3131
expect(getByText('Hello, world!')).toBeTruthy();
32-
expect(container.toJSON()).toMatchInlineSnapshot(`
33-
<Text>Hello, World!</Text>
32+
expect(toJSON(container)).toMatchInlineSnapshot(`
33+
<View
34+
testID="ntl-container"
35+
>
36+
<Text>Hello, World!</Text>
37+
</View>
3438
`);
3539
});
3640
```
@@ -83,20 +87,17 @@ const { getByText, getByTestId /* etc */ } = render(<Component />);
8387

8488
### `container`
8589

86-
The `ReactTestRendererInstance` result from your render. This has helpful methods like `toTree()`
87-
and `toJSON()`.
88-
89-
> You should rarely use the container. There are very few instances where you need to access the
90-
> container itself to do something you'd need to in a test.
90+
`native-testing-library` will create a View to wrap your react component passed to render. This
91+
ensures that there is always a single child passed to the `AppContainer` component.
9192

9293
### `baseElement`
9394

94-
This is the root element of your render result. By default, this is what all of your queries will be
95-
run on, and you could also use it to do any custom searching logic you wanted to..
95+
This is the root element of your render result. This element is an `AppContainer` from
96+
`react-native`, and it appears as two nested `Views` at the root of your render.
9697

9798
### `debug`
9899

99-
This method is a shortcut for `console.log(prettyPrint(container.toJSON()))`.
100+
This method is a shortcut for `console.log(prettyPrint(toJSON(baseElement)))`.
100101

101102
```javascript
102103
import { render } from 'native-testing-library';
@@ -112,6 +113,7 @@ debug();
112113
// Hello World
113114
// </Text>
114115
// </View>
116+
// you can also pass an element: debug(getByText('Hello World'))
115117
```
116118

117119
This is a simple wrapper around `prettyPrint` which is also exported.
@@ -136,8 +138,7 @@ rerender(<NumberDisplay number={2} />);
136138

137139
This will cause the rendered component to be unmounted. This is useful for testing what happens when
138140
your component is removed from the page (like testing that you don't leave event handlers hanging
139-
around causing memory leaks). Note that you don't need to call this `afterEach` like you do in react
140-
testing library because these elements aren't being added to a DOM. Use it only as necessary.
141+
around causing memory leaks).
141142

142143
> This method is a wrapper around ReactTestRenderer.unmount()
143144
@@ -147,3 +148,33 @@ import { render } from 'native-testing-library';
147148
const { unmount } = render(<Login />);
148149
unmount();
149150
```
151+
152+
---
153+
154+
## `cleanup`
155+
156+
Unmounts React trees that were mounted with [render](#render).
157+
158+
```jsx
159+
import { cleanup, render } from 'native-testing-library';
160+
161+
afterEach(cleanup); // <-- add this
162+
163+
test('renders into document', () => {
164+
render(<View />);
165+
// ...
166+
});
167+
168+
// ... more tests ...
169+
```
170+
171+
**If you don't want to add this to _every single test file_** then we recommend that you configure
172+
your test framework to run a file before your tests which does this automatically.
173+
174+
---
175+
176+
## `act`
177+
178+
This is a light wrapper around the
179+
[`react-test-renderer` `act` function](https://reactjs.org/docs/test-renderer.html). All it does is
180+
forward all arguments to the act function if your version of react supports `act`.

docs/api-queries.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,6 @@ title: Queries
44
sidebar_label: Queries
55
---
66

7-
## Using queries
8-
9-
All queries are exported directly from the entry point, but you likely won't need to use them that
10-
way in most cases. For instance, you can do the following:
11-
12-
```javascript
13-
import { getByText } from 'native-testing-library';
14-
15-
getByText(container, 'hello world');
16-
```
17-
18-
but you likely won't need to. Most queries you will run are on the result of render. You can use
19-
those in this way:
20-
21-
```javascript
22-
const { getByText } = render(<Text>hello world</Text>);
23-
24-
getByText('hello world');
25-
```
26-
27-
This page is written in the format of the first example because it is documentation for the query
28-
API, not documentation for the render result.
29-
307
## Variants
318

329
> `getBy` queries are shown by default in the [query documentation](#queries) below.
@@ -85,7 +62,7 @@ See [TextMatch](#textmatch) for documentation on what can be passed to a query.
8562
8663
```typescript
8764
getByHintText(
88-
testRenderer: ReactTestRendererInstance,
65+
container: ReactTestRenderer | NativeTestInstance,
8966
match: TextMatch,
9067
options?: {
9168
exact?: boolean = true,
@@ -114,7 +91,7 @@ getByHintText('summary'); // returns the View node
11491
11592
```typescript
11693
getByLabelText(
117-
testRenderer: ReactTestRendererInstance,
94+
container: ReactTestRenderer | NativeTestInstance,
11895
match: TextMatch,
11996
options?: {
12097
exact?: boolean = true,
@@ -153,7 +130,7 @@ getByLabelText('username'); // returns the TextInput node
153130
154131
```typescript
155132
getByRole(
156-
testRenderer: ReactTestRendererInstance,
133+
container: ReactTestRenderer | NativeTestInstance,
157134
match: TextMatch,
158135
options?: {
159136
selector?: SelectorFn,
@@ -181,7 +158,7 @@ getByRole('summary'); // returns the View node
181158
182159
```typescript
183160
getByPlaceholderText(
184-
testRenderer: ReactTestRendererInstance,
161+
container: ReactTestRenderer | NativeTestInstance,
185162
match: TextMatch,
186163
options?: {
187164
exact?: boolean = true,
@@ -209,7 +186,7 @@ getByPlaceholderText('Username'); // returns the TextInput node
209186
210187
```typescript
211188
getByText(
212-
testRenderer: ReactTestRendererInstance,
189+
container: ReactTestRenderer | NativeTestInstance,
213190
match: TextMatch,
214191
options?: {
215192
exact?: boolean = true,
@@ -238,7 +215,7 @@ getByText(/about/i); // returns the Text node
238215
239216
```typescript
240217
getByTitle(
241-
testRenderer: ReactTestRendererInstance,
218+
container: ReactTestRenderer | NativeTestInstance,
242219
match: TextMatch,
243220
options?: {
244221
exact?: boolean = true,
@@ -266,7 +243,7 @@ getByTitle(/about/i); // returns the Button node
266243
267244
```typescript
268245
getByValue(
269-
testRenderer: ReactTestRendererInstance,
246+
container: ReactTestRenderer | NativeTestInstance,
270247
match: TextMatch,
271248
options?: {
272249
exact?: boolean = true,
@@ -294,7 +271,7 @@ getByValue(/about/i); // returns the Input node
294271
295272
```typescript
296273
getByTestId(
297-
testRenderer: ReactTestRendererInstance,
274+
container: ReactTestRenderer | NativeTestInstance,
298275
match: TextMatch,
299276
options?: {
300277
trim?: boolean = true,

docs/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
id: intro
33
title: Introduction
4-
sidebar_label: Intro
4+
sidebar_label: Introduction
55
---
66

77
## The problem

docs/setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ file that re-exports everything from `native-testing-library`. You can replace
2424
[below](#configuring-jest-with-test-utils) for a way to make your test util file accessible without
2525
using relative paths.
2626

27-
The example below sets up data providers using the [`wrapper`](api-render.md#render-options) option
28-
to `render`.
27+
The example below sets up data providers using the [`wrapper`](api-main.md#render-options) option to
28+
`render`.
2929

3030
```diff
3131
// my-component.test.js

website/pages/en/versions.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ function Versions(props) {
3333
<tr>
3434
<th>{latestVersion}</th>
3535
<td>
36-
<a href="">Documentation</a>
36+
<a href="/docs/intro">Documentation</a>
3737
</td>
3838
<td>
39-
<a href="">Release Notes</a>
39+
<a href="https://github.com/testing-library/native-testing-library/releases/latest">
40+
Changelog
41+
</a>
4042
</td>
4143
</tr>
4244
</tbody>
@@ -45,6 +47,17 @@ function Versions(props) {
4547
This is the version that is configured automatically when you first install this
4648
project.
4749
</p>
50+
<h3 id="latest">Next version</h3>
51+
<table className="versions">
52+
<tbody>
53+
<tr>
54+
<th>next</th>
55+
<td>
56+
<a href="/docs/next/intro">Documentation</a>
57+
</td>
58+
</tr>
59+
</tbody>
60+
</table>
4861
<h3 id="archive">Past Versions</h3>
4962
<table className="versions">
5063
<tbody>
@@ -56,7 +69,7 @@ function Versions(props) {
5669
<td>
5770
{/* You are supposed to fill this href by yourself
5871
Example: href={`docs/${version}/doc.html`} */}
59-
<a href={`docs/${version}/doc.html`}>Documentation</a>
72+
<a href={`docs/${version}/intro`}>Documentation</a>
6073
</td>
6174
<td>
6275
<a href={`${repoUrl}/releases/tag/v${version}`}>Changelog</a>

website/sidebars.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
"guiding-principles",
99
"cheat-sheet"
1010
],
11-
"API": [
12-
"api-queries",
13-
"api-events",
14-
"api-async",
15-
"api-helpers",
16-
"api-render",
17-
"api-act"
18-
],
11+
"API": ["api-main", "api-queries", "api-events", "api-async", "api-helpers"],
1912
"Ecosystem": ["ecosystem-jest-native", "ecosystem-jest-preset"]
2013
},
2114
"recipes": {

website/siteConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//];
2222

2323
const siteConfig = {
24-
title: 'React Native Testing Library', // Title for your website.
24+
title: 'Native Testing Library', // Title for your website.
2525
tagline:
2626
'Simple and complete React Native testing utilities that encourage good testing practices.',
2727
url: 'https://native-testing-library.com', // Your website URL
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: version-3.0.0-api-act
3+
title: Act
4+
sidebar_label: Act
5+
original_id: api-act
6+
---
7+
8+
## `act`
9+
10+
This is a light wrapper around the
11+
[`react-test-renderer` `act` function](https://reactjs.org/docs/test-renderer.html). All it does is
12+
forward all arguments to the act function if your version of react supports `act`.

0 commit comments

Comments
 (0)