Skip to content

Commit fb8a6fc

Browse files
committed
chore(docs): improve examples to use better APIs
1 parent 8778012 commit fb8a6fc

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function setAnswer(question, answer) {
4444
}
4545

4646
test('should verify two questions', () => {
47-
const { getAllByType, getByText } = render(<QuestionsBoard {...props} />);
48-
const allQuestions = getAllByType(Question);
47+
const { getAllByA11yRole, getByText } = render(<QuestionsBoard {...props} />);
48+
const allQuestions = getAllByA11yRole('header');
4949

5050
setAnswer(allQuestions[0], 'a1');
5151
setAnswer(allQuestions[1], 'a2');

docs/API.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ Deeply renders given React element and returns helpers to query the output compo
2727

2828
```jsx
2929
import { render } from 'react-native-testing-library';
30+
import { QuestionsBoard } from '../QuestionsBoard';
3031

31-
const { getByTestId, getByText /*...*/ } = render(<Component />);
32+
test('should verify two questions', () => {
33+
const { queryAllByA11yRole } = render(<QuestionsBoard {...props} />);
34+
const allQuestions = queryAllByA11yRole('header');
35+
36+
expect(allQuestions).toHaveLength(2);
37+
});
3238
```
3339

40+
> When using React context providers, like Redux Provider, you'll likely want to wrap rendered component with them. In such cases it's convenient to create your custom `render` method. [Follow this great guide on how to set this up](https://testing-library.com/docs/react-testing-library/setup#custom-render).
41+
3442
The `render` method returns a `RenderResult` object that has a few properties:
3543

3644
### `...queries`
@@ -42,7 +50,9 @@ See [Queries](./Queries.md) for a complete list.
4250
#### Example
4351

4452
```jsx
45-
const { getByText, queryByA11yRole } = render(<Component />);
53+
import { render } from 'react-native-testing-library';
54+
55+
const { getByText, queryByA11yStates } = render(<Component />);
4656
```
4757

4858
### `update`
@@ -66,8 +76,6 @@ unmount(): void
6676

6777
Unmount the in-memory tree, triggering the appropriate lifecycle events
6878

69-
When using React context providers, like Redux Provider, you'll likely want to wrap rendered component with them. In such cases it's convenient to create your custom `render` method. [Follow this great guide on how to set this up](https://github.com/kentcdodds/react-testing-library#custom-render).
70-
7179
### `debug`
7280

7381
```ts

docs/GettingStarted.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ function setAnswer(question, answer) {
2929
}
3030

3131
test('should verify two questions', () => {
32-
const { getAllByType, getByText } = render(<QuestionsBoard {...props} />);
33-
const allQuestions = getAllByType(Question);
32+
jest.spyOn(props, 'verifyQuestions');
33+
const { getAllByA11yRole, getByText } = render(<QuestionsBoard {...props} />);
34+
const allQuestions = getAllByA11yRole('header');
3435

3536
setAnswer(allQuestions[0], 'a1');
3637
setAnswer(allQuestions[1], 'a2');

0 commit comments

Comments
 (0)