|
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:
674 bytes
|
| Line | |
|---|
| 1 | # Suggest using `toHaveLength()` (`prefer-to-have-length`)
|
|---|
| 2 |
|
|---|
| 3 | In order to have a better failure message, `toHaveLength()` should be used upon
|
|---|
| 4 | asserting expectations on objects length property.
|
|---|
| 5 |
|
|---|
| 6 | ## Rule details
|
|---|
| 7 |
|
|---|
| 8 | This rule triggers a warning if `toBe()`, `toEqual()` or `toStrictEqual()` is
|
|---|
| 9 | used to assert objects length property.
|
|---|
| 10 |
|
|---|
| 11 | ```js
|
|---|
| 12 | expect(files.length).toBe(1);
|
|---|
| 13 | ```
|
|---|
| 14 |
|
|---|
| 15 | This rule is enabled by default.
|
|---|
| 16 |
|
|---|
| 17 | ### Default configuration
|
|---|
| 18 |
|
|---|
| 19 | The following patterns are considered warnings:
|
|---|
| 20 |
|
|---|
| 21 | ```js
|
|---|
| 22 | expect(files.length).toBe(1);
|
|---|
| 23 |
|
|---|
| 24 | expect(files.length).toEqual(1);
|
|---|
| 25 |
|
|---|
| 26 | expect(files.length).toStrictEqual(1);
|
|---|
| 27 | ```
|
|---|
| 28 |
|
|---|
| 29 | The following pattern is not warning:
|
|---|
| 30 |
|
|---|
| 31 | ```js
|
|---|
| 32 | expect(files).toHaveLength(1);
|
|---|
| 33 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.