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