source: frontend/node_modules/eslint-plugin-jest/docs/rules/prefer-called-with.md

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