|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
998 bytes
|
| Rev | Line | |
|---|
| [9af201e] | 1 | # Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`prefer-called-with`)
|
|---|
| 2 |
|
|---|
| 3 | The `toBeCalled()` matcher is used to assert that a mock function has been
|
|---|
| 4 | called one or more times, without checking the arguments passed. The assertion
|
|---|
| 5 | is stronger when arguments are also validated using the `toBeCalledWith()`
|
|---|
| 6 | matcher. When some arguments are difficult to check, using generic match like
|
|---|
| 7 | `expect.anything()` at least enforces number and position of arguments.
|
|---|
| 8 |
|
|---|
| 9 | This rule warns if the form without argument checking is used, except for `.not`
|
|---|
| 10 | enforcing a function has never been called.
|
|---|
| 11 |
|
|---|
| 12 | ## Rule details
|
|---|
| 13 |
|
|---|
| 14 | The following patterns are warnings:
|
|---|
| 15 |
|
|---|
| 16 | ```js
|
|---|
| 17 | expect(someFunction).toBeCalled();
|
|---|
| 18 |
|
|---|
| 19 | expect(someFunction).toHaveBeenCalled();
|
|---|
| 20 | ```
|
|---|
| 21 |
|
|---|
| 22 | The following patterns are not warnings:
|
|---|
| 23 |
|
|---|
| 24 | ```js
|
|---|
| 25 | expect(noArgsFunction).toBeCalledWith();
|
|---|
| 26 |
|
|---|
| 27 | expect(roughArgsFunction).toBeCalledWith(expect.anything(), expect.any(Date));
|
|---|
| 28 |
|
|---|
| 29 | expect(anyArgsFunction).toBeCalledTimes(1);
|
|---|
| 30 |
|
|---|
| 31 | expect(uncalledFunction).not.toBeCalled();
|
|---|
| 32 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.