7
7
## Rule Details
8
8
9
9
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.
13
17
14
18
Example of ** incorrect** code for this rule:
15
19
16
20
``` js
17
21
const foo = async () => {
18
22
await waitFor (() => {
19
23
expect (a).toEqual (' a' );
20
- expect (b ).toEqual (' b ' );
24
+ expect (a ).toEqual (' a ' );
21
25
});
22
26
23
27
// or
24
28
await waitFor (function () {
25
29
expect (a).toEqual (' a' );
26
- expect (b ).toEqual (' b ' );
30
+ expect (a ).toEqual (' a ' );
27
31
});
28
32
};
29
33
```
@@ -33,13 +37,13 @@ Examples of **correct** code for this rule:
33
37
``` js
34
38
const foo = async () => {
35
39
await waitFor (() => expect (a).toEqual (' a' ));
36
- expect (b ).toEqual (' b ' );
40
+ expect (a ).toEqual (' a ' );
37
41
38
42
// or
39
43
await waitFor (function () {
40
44
expect (a).toEqual (' a' );
41
45
});
42
- expect (b ).toEqual (' b ' );
46
+ expect (a ).toEqual (' a ' );
43
47
44
48
// it only detects expect
45
49
// so this case doesn't generate warnings
0 commit comments