| 1 | # Disallow alias methods (`no-alias-methods`)
|
|---|
| 2 |
|
|---|
| 3 | Several Jest methods have alias names, such as `toThrow` having the alias of
|
|---|
| 4 | `toThrowError`. This rule ensures that only the canonical name as used in the
|
|---|
| 5 | Jest documentation is used in the code. This makes it easier to search for all
|
|---|
| 6 | occurrences of the method within code, and it ensures consistency among the
|
|---|
| 7 | method names used.
|
|---|
| 8 |
|
|---|
| 9 | ## Rule details
|
|---|
| 10 |
|
|---|
| 11 | This rule triggers a warning if the alias name, rather than the canonical name,
|
|---|
| 12 | of a method is used.
|
|---|
| 13 |
|
|---|
| 14 | ### Default configuration
|
|---|
| 15 |
|
|---|
| 16 | The following patterns are considered warnings:
|
|---|
| 17 |
|
|---|
| 18 | ```js
|
|---|
| 19 | expect(a).toBeCalled();
|
|---|
| 20 | expect(a).toBeCalledTimes();
|
|---|
| 21 | expect(a).toBeCalledWith();
|
|---|
| 22 | expect(a).lastCalledWith();
|
|---|
| 23 | expect(a).nthCalledWith();
|
|---|
| 24 | expect(a).toReturn();
|
|---|
| 25 | expect(a).toReturnTimes();
|
|---|
| 26 | expect(a).toReturnWith();
|
|---|
| 27 | expect(a).lastReturnedWith();
|
|---|
| 28 | expect(a).nthReturnedWith();
|
|---|
| 29 | expect(a).toThrowError();
|
|---|
| 30 | ```
|
|---|
| 31 |
|
|---|
| 32 | The following patterns are not considered warnings:
|
|---|
| 33 |
|
|---|
| 34 | ```js
|
|---|
| 35 | expect(a).toHaveBeenCalled();
|
|---|
| 36 | expect(a).toHaveBeenCalledTimes();
|
|---|
| 37 | expect(a).toHaveBeenCalledWith();
|
|---|
| 38 | expect(a).toHaveBeenLastCalledWith();
|
|---|
| 39 | expect(a).toHaveBeenNthCalledWith();
|
|---|
| 40 | expect(a).toHaveReturned();
|
|---|
| 41 | expect(a).toHaveReturnedTimes();
|
|---|
| 42 | expect(a).toHaveReturnedWith();
|
|---|
| 43 | expect(a).toHaveLastReturnedWith();
|
|---|
| 44 | expect(a).toHaveNthReturnedWith();
|
|---|
| 45 | expect(a).toThrow();
|
|---|
| 46 | ```
|
|---|