You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,7 @@ To enable this configuration use the `extends` property in your
137
137
|[no-dom-import](docs/rules/no-dom-import.md)| Disallow importing from DOM Testing Library |![angular-badge][]![react-badge][]![vue-badge][]|![fixable-badge][]|
138
138
|[no-manual-cleanup](docs/rules/no-manual-cleanup.md)| Disallow the use of `cleanup`|||
139
139
|[no-multiple-assertions-wait-for](docs/rules/no-multiple-assertions-wait-for.md)| Disallow the use of multiple expect inside `waitFor`|||
140
+
|[no-node-access](docs/rules/no-node-access.md)| Disallow direct Node access |![angular-badge][]![react-badge][]![vue-badge][]|||
140
141
|[no-promise-in-fire-event](docs/rules/no-promise-in-fire-event.md)| Disallow the use of promises passed to a `fireEvent` method |||
141
142
|[no-wait-for-empty-callback](docs/rules/no-wait-for-empty-callback.md)| Disallow empty callbacks for `waitFor` and `waitForElementToBeRemoved`|![dom-badge][]![angular-badge][]![react-badge][]![vue-badge][]||
142
143
|[prefer-explicit-assert](docs/rules/prefer-explicit-assert.md)| Suggest using explicit assertions rather than just `getBy*` queries |||
The Testing Library already provides methods for querying DOM elements.
4
+
5
+
## Rule Details
6
+
7
+
This rule aims to disallow DOM traversal using native HTML methods and properties, such as `closest`, `lastChild` and all that returns another Node element from an HTML tree.
8
+
9
+
Examples of **incorrect** code for this rule:
10
+
11
+
```js
12
+
import { screen } from'@testing-library/react';
13
+
14
+
screen.getByText('Submit').closest('button'); // chaining with Testing Library methods
15
+
```
16
+
17
+
```js
18
+
import { screen } from'@testing-library/react';
19
+
20
+
constbuttons=screen.getAllByRole('button');
21
+
expect(buttons[1].lastChild).toBeInTheDocument();
22
+
```
23
+
24
+
```js
25
+
import { screen } from'@testing-library/react';
26
+
27
+
constbuttonText=screen.getByText('Submit');
28
+
constbutton=buttonText.closest('button');
29
+
```
30
+
31
+
Examples of **correct** code for this rule:
32
+
33
+
```js
34
+
import { screen } from'@testing-library/react';
35
+
36
+
constbutton=screen.getByRole('button');
37
+
expect(button).toHaveTextContent('submit');
38
+
```
39
+
40
+
```js
41
+
import { render, within } from'@testing-library/react';
0 commit comments