Skip to content

Commit 9a7199b

Browse files
committed
docs: update sample code
1 parent ed30651 commit 9a7199b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Example of **incorrect** code for this rule:
2020
```js
2121
const foo = async () => {
2222
await waitFor(() => {
23-
expect(a).toEqual('a');
24-
expect(a).toEqual('a');
23+
expect(window.fetch).toHaveBeenCalledWith('/foo');
24+
expect(window.fetch).toHaveBeenCalledWith('/foo');
2525
});
2626

2727
// or
2828
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');
3131
});
3232
};
3333
```
@@ -36,20 +36,26 @@ Examples of **correct** code for this rule:
3636

3737
```js
3838
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);
4141

4242
// or
4343
await waitFor(function () {
44-
expect(a).toEqual('a');
44+
expect(window.fetch).toHaveBeenCalledWith('foo');
4545
});
46-
expect(a).toEqual('a');
46+
expect(window.fetch).toHaveBeenCalledTimes(1);
4747

4848
// it only detects expect
4949
// so this case doesn't generate warnings
5050
await waitFor(() => {
5151
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');
5359
});
5460
};
5561
```

0 commit comments

Comments
 (0)