source: frontend/node_modules/eslint-plugin-jest/docs/rules/prefer-to-contain.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: 862 bytes
Line 
1# Suggest using `toContain()` (`prefer-to-contain`)
2
3In order to have a better failure message, `toContain()` should be used upon
4asserting expectations on an array containing an object.
5
6## Rule details
7
8This rule triggers a warning if `toBe()`, `toEqual()` or `toStrictEqual()` is
9used to assert object inclusion in an array
10
11```js
12expect(a.includes(b)).toBe(true);
13```
14
15```js
16expect(a.includes(b)).not.toBe(true);
17```
18
19```js
20expect(a.includes(b)).toBe(false);
21```
22
23### Default configuration
24
25The following patterns are considered warnings:
26
27```js
28expect(a.includes(b)).toBe(true);
29
30expect(a.includes(b)).not.toBe(true);
31
32expect(a.includes(b)).toBe(false);
33
34expect(a.includes(b)).toEqual(true);
35
36expect(a.includes(b)).toStrictEqual(true);
37```
38
39The following patterns are not considered warnings:
40
41```js
42expect(a).toContain(b);
43
44expect(a).not.toContain(b);
45```
Note: See TracBrowser for help on using the repository browser.