|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
735 bytes
|
| Line | |
|---|
| 1 | # Suggest using the built-in equality matchers (`prefer-equality-matcher`)
|
|---|
| 2 |
|
|---|
| 3 | Jest has built-in matchers for expecting equality which allow for more readable
|
|---|
| 4 | tests and error messages if an expectation fails.
|
|---|
| 5 |
|
|---|
| 6 | ## Rule details
|
|---|
| 7 |
|
|---|
| 8 | This rule checks for _strict_ equality checks (`===` & `!==`) in tests that
|
|---|
| 9 | could be replaced with one of the following built-in equality matchers:
|
|---|
| 10 |
|
|---|
| 11 | - `toBe`
|
|---|
| 12 | - `toEqual`
|
|---|
| 13 | - `toStrictEqual`
|
|---|
| 14 |
|
|---|
| 15 | Examples of **incorrect** code for this rule:
|
|---|
| 16 |
|
|---|
| 17 | ```js
|
|---|
| 18 | expect(x === 5).toBe(true);
|
|---|
| 19 | expect(name === 'Carl').not.toEqual(true);
|
|---|
| 20 | expect(myObj !== thatObj).toStrictEqual(true);
|
|---|
| 21 | ```
|
|---|
| 22 |
|
|---|
| 23 | Examples of **correct** code for this rule:
|
|---|
| 24 |
|
|---|
| 25 | ```js
|
|---|
| 26 | expect(x).toBe(5);
|
|---|
| 27 | expect(name).not.toEqual('Carl');
|
|---|
| 28 | expect(myObj).toStrictEqual(thatObj);
|
|---|
| 29 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.