@@ -20,14 +20,14 @@ Example of **incorrect** code for this rule:
20
20
``` js
21
21
const foo = async () => {
22
22
await waitFor (() => {
23
- expect (a). toEqual ( ' a ' );
24
- expect (a). toEqual ( ' a ' );
23
+ expect (window . fetch ). toHaveBeenCalledWith ( ' /foo ' );
24
+ expect (window . fetch ). toHaveBeenCalledWith ( ' /foo ' );
25
25
});
26
26
27
27
// or
28
28
await waitFor (function () {
29
- expect (a). toEqual ( ' a ' );
30
- expect (a). toEqual ( ' a ' );
29
+ expect (window . fetch ). toHaveBeenCalledWith ( ' /foo ' );
30
+ expect (window . fetch ). toHaveBeenCalledWith ( ' /foo ' );
31
31
});
32
32
};
33
33
```
@@ -36,20 +36,26 @@ Examples of **correct** code for this rule:
36
36
37
37
``` js
38
38
const foo = async () => {
39
- await waitFor (() => expect (a). toEqual ( ' a ' ));
40
- expect (a). toEqual ( ' a ' );
39
+ await waitFor (() => expect (window . fetch ). toHaveBeenCalledWith ( ' foo ' ));
40
+ expect (window . fetch ). toHaveBeenCalledTimes ( 1 );
41
41
42
42
// or
43
43
await waitFor (function () {
44
- expect (a). toEqual ( ' a ' );
44
+ expect (window . fetch ). toHaveBeenCalledWith ( ' foo ' );
45
45
});
46
- expect (a). toEqual ( ' a ' );
46
+ expect (window . fetch ). toHaveBeenCalledTimes ( 1 );
47
47
48
48
// it only detects expect
49
49
// so this case doesn't generate warnings
50
50
await waitFor (() => {
51
51
fireEvent .keyDown (input, { key: ' ArrowDown' });
52
- expect (b).toEqual (' b' );
52
+ expect (window .fetch ).toHaveBeenCalledTimes (1 );
53
+ });
54
+
55
+ // different async targets so the rule does not report it
56
+ await waitFor (() => {
57
+ expect (window .fetch ).toHaveBeenCalledWith (' /foo' );
58
+ expect (localStorage .setItem ).toHaveBeenCalledWith (' bar' , ' baz' );
53
59
});
54
60
};
55
61
```
0 commit comments