Skip to content

Commit 9b252f8

Browse files
docs: update docs about eslint rule (#1578)
* fix: relevant issues indicated by the eslint rule * chore: rename file * docs: move eslint to getting-started; cleanup legacy stuff
1 parent 2a25531 commit 9b252f8

File tree

5 files changed

+41
-50
lines changed

5 files changed

+41
-50
lines changed

src/queries/__tests__/label-text.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('getByLabelText, queryByLabelText, findByLabelText', async () => {
4242
render(<Section />);
4343

4444
expect(screen.getByLabelText(BUTTON_LABEL).props.accessibilityLabel).toEqual(BUTTON_LABEL);
45-
const button = screen.queryByLabelText(/button/g);
45+
const button = screen.queryByLabelText(/button/);
4646
expect(button?.props.accessibilityLabel).toEqual(BUTTON_LABEL);
4747

4848
expect(() => screen.getByLabelText(NO_MATCHES_TEXT)).toThrow(
@@ -72,7 +72,7 @@ test('getAllByLabelText, queryAllByLabelText, findAllByLabelText', async () => {
7272
render(<Section />);
7373

7474
expect(screen.getAllByLabelText(TEXT_LABEL)).toHaveLength(2);
75-
expect(screen.queryAllByLabelText(/cool/g)).toHaveLength(3);
75+
expect(screen.queryAllByLabelText(/cool/)).toHaveLength(3);
7676

7777
expect(() => screen.getAllByLabelText(NO_MATCHES_TEXT)).toThrow(
7878
getNoInstancesFoundMessage(NO_MATCHES_TEXT),
@@ -89,7 +89,7 @@ test('getAllByLabelText, queryAllByLabelText, findAllByLabelText with exact as f
8989
render(<Section />);
9090

9191
expect(screen.getAllByLabelText(TEXT_LABEL, { exact: false })).toHaveLength(2);
92-
expect(screen.queryAllByLabelText(/cool/g, { exact: false })).toHaveLength(3);
92+
expect(screen.queryAllByLabelText(/cool/, { exact: false })).toHaveLength(3);
9393

9494
expect(() => screen.getAllByLabelText(NO_MATCHES_TEXT, { exact: false })).toThrow(
9595
getNoInstancesFoundMessage(NO_MATCHES_TEXT),

src/queries/__tests__/role.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test('getByRole, queryByRole, findByRole', async () => {
4444
render(<Section />);
4545

4646
expect(screen.getByRole('button').props.accessibilityRole).toEqual('button');
47-
const button = screen.queryByRole(/button/g);
47+
const button = screen.queryByRole(/button/);
4848
expect(button?.props.accessibilityRole).toEqual('button');
4949

5050
expect(() => screen.getByRole(NO_MATCHES_TEXT)).toThrow(
@@ -68,7 +68,7 @@ test('getAllByRole, queryAllByRole, findAllByRole', async () => {
6868
render(<Section />);
6969

7070
expect(screen.getAllByRole('link')).toHaveLength(2);
71-
expect(screen.queryAllByRole(/ink/g)).toHaveLength(2);
71+
expect(screen.queryAllByRole(/ink/)).toHaveLength(2);
7272

7373
expect(() => screen.getAllByRole(NO_MATCHES_TEXT)).toThrow(
7474
getNoInstancesFoundMessage(NO_MATCHES_TEXT),

website/docs/EslintPLluginTestingLibrary.md

Lines changed: 0 additions & 28 deletions
This file was deleted.

website/docs/GettingStarted.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ id: getting-started
33
title: Getting Started
44
---
55

6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
69
## The problem
710

811
You want to write maintainable tests for your React Native components. As a part of this goal, you want your tests to avoid including implementation details of your components and focus on making your tests give you the confidence they are intended. As part of this, you want your tests to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
@@ -21,38 +24,54 @@ You can find the source of the `QuestionsBoard` component and this example [here
2124

2225
Open a Terminal in your project's folder and run:
2326

24-
#### Using `yarn`
25-
27+
<Tabs groupId="package-manager">
28+
<TabItem value="npm" label="npm">
2629
```sh
27-
yarn add --dev @testing-library/react-native
30+
npm install --save-dev @testing-library/react-native
2831
```
29-
30-
#### Using `npm`
31-
32+
</TabItem>
33+
<TabItem value="yarn" label="yarn">
3234
```sh
33-
npm install --save-dev @testing-library/react-native
35+
yarn add --dev @testing-library/react-native
3436
```
37+
</TabItem>
38+
</Tabs>
3539

3640
This library has a peer dependency for `react-test-renderer` package. Make sure that your `react-test-renderer` version matches exactly your `react` version.
3741

38-
:::info
39-
To properly use helpers for async tests (`findBy` queries and `waitFor`), you need at least React >=16.9.0 (featuring async `act`) or React Native >=0.61 (which comes with React >=16.9.0).
40-
:::
42+
### Jest matchers
4143

42-
### Additional Jest matchers
43-
44-
To use additional React Native-specific Jest matchers, add the following line to your `jest-setup.ts` file (configured using [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array)):
44+
To set up React Native-specific Jest matchers, add the following line to your `jest-setup.ts` file (configured using [`setupFilesAfterEnv`](https://jestjs.io/docs/configuration#setupfilesafterenv-array)):
4545

4646
```ts
4747
import '@testing-library/react-native/extend-expect';
4848
```
4949

50-
### Flow
50+
### ESLint plugin
51+
52+
We recommend setting up [`eslint-plugin-testing-library`](https://github.com/testing-library/eslint-plugin-testing-library) package to help you avoid common Testing Library mistakes and bad practices.
5153

52-
Note for [Flow](https://flow.org) users – you'll also need to install typings for `react-test-renderer`:
54+
Install the plugin (assuming you already have `eslint` installed & configured):
5355

56+
<Tabs groupId="package-manager">
57+
<TabItem value="npm" label="npm">
58+
```sh
59+
npm install --save-dev eslint-plugin-testing-library
60+
```
61+
</TabItem>
62+
<TabItem value="yarn" label="yarn">
5463
```sh
55-
flow-typed install react-test-renderer
64+
yarn add --dev eslint-plugin-testing-library
65+
```
66+
</TabItem>
67+
</Tabs>
68+
69+
Then, add relevant entry to your ESLint config (e.g., `.eslintrc.js`). We recommend extending the `react` plugin:
70+
71+
```js
72+
module.exports = {
73+
extends: ['plugin:testing-library/react'],
74+
};
5675
```
5776

5877
## Example

website/sidebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
docs: {
33
Introduction: ['getting-started'],
44
'API Reference': ['api', 'api-queries', 'user-event', 'jest-matchers'],
5-
Guides: ['how-should-i-query', 'troubleshooting', 'faq', 'eslint-plugin-testing-library'],
5+
Guides: ['how-should-i-query', 'troubleshooting', 'faq'],
66
Advanced: ['testing-env', 'understanding-act'],
77
Community: ['community-resources'],
88
Migrations: [

0 commit comments

Comments
 (0)