File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ When asserting against primitive literals such as numbers and strings, the
44equality matchers all operate the same, but read slightly differently in code.
55
66This rule recommends using the ` toBe ` matcher in these situations, as it forms
7- the most grammatically natural sentence.
7+ the most grammatically natural sentence. For ` null ` , ` undefined ` , and ` NaN ` this
8+ rule recommends using their specific ` toBe ` matchers, as they give better error
9+ messages as well.
810
911## Rule details
1012
@@ -28,3 +30,23 @@ expect(loadMessage()).resolves.toBe('hello world');
2830
2931expect (catchError ()).toStrictEqual ({ message: ' oh noes!' });
3032```
33+
34+ For ` null ` , ` undefined ` , and ` NaN ` , this rule triggers a warning if ` toBe ` is
35+ used to assert against those literal values instead of their more specific
36+ ` toBe ` counterparts:
37+
38+ ``` js
39+ expect (value).not .toBe (undefined );
40+ expect (getMessage ()).toBe (null );
41+ expect (countMessages ()).resolves .not .toBe (NaN );
42+ ```
43+
44+ The following pattern is not warning:
45+
46+ ``` js
47+ expect (value).toBeDefined ();
48+ expect (getMessage ()).toBeNull ();
49+ expect (countMessages ()).resolves .not .toBeNaN ();
50+
51+ expect (catchError ()).toStrictEqual ({ message: undefined });
52+ ```
You can’t perform that action at this time.
0 commit comments