Skip to content

Commit 151d65c

Browse files
committed
docs: update doc
1 parent a3eca9d commit 151d65c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/rules/no-wait-for-multiple-assertions.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@
77
## Rule Details
88

99
This rule aims to ensure the correct usage of `expect` inside `waitFor`, in the way that they're intended to be used.
10-
When using multiple assertions inside `waitFor`, if one fails, you have to wait for a timeout before seeing it failing.
11-
Putting one assertion, you can both wait for the UI to settle to the state you want to assert on,
12-
and also fail faster if one of the assertions do end up failing
10+
11+
If you use multiple assertions against the **same asynchronous target** inside `waitFor`,
12+
you may have to wait for a timeout before seeing a test failure, which is inefficient.
13+
Therefore, you should avoid using multiple assertions on the same async target inside a single `waitFor` callback.
14+
15+
However, multiple assertions against **different async targets** (for example, independent state updates or different function calls) are allowed.
16+
This avoids unnecessary verbosity and maintains readability, without increasing the risk of missing failures.
1317

1418
Example of **incorrect** code for this rule:
1519

1620
```js
1721
const foo = async () => {
1822
await waitFor(() => {
1923
expect(a).toEqual('a');
20-
expect(b).toEqual('b');
24+
expect(a).toEqual('a');
2125
});
2226

2327
// or
2428
await waitFor(function () {
2529
expect(a).toEqual('a');
26-
expect(b).toEqual('b');
30+
expect(a).toEqual('a');
2731
});
2832
};
2933
```
@@ -33,13 +37,13 @@ Examples of **correct** code for this rule:
3337
```js
3438
const foo = async () => {
3539
await waitFor(() => expect(a).toEqual('a'));
36-
expect(b).toEqual('b');
40+
expect(a).toEqual('a');
3741

3842
// or
3943
await waitFor(function () {
4044
expect(a).toEqual('a');
4145
});
42-
expect(b).toEqual('b');
46+
expect(a).toEqual('a');
4347

4448
// it only detects expect
4549
// so this case doesn't generate warnings

0 commit comments

Comments
 (0)