diff --git a/docs/rules/prefer-to-be-null.md b/docs/rules/prefer-to-be-null.md index 0f42c2714..7c0f96bcc 100644 --- a/docs/rules/prefer-to-be-null.md +++ b/docs/rules/prefer-to-be-null.md @@ -5,7 +5,8 @@ asserting expections on null value. ## Rule details -This rule triggers a warning if `toBe()` is used to assert a null value. +This rule triggers a warning if `toBe()`, `isEqual()` or `toStrictEqual()` is +used to assert a null value. ```js expect(null).toBe(null); @@ -15,10 +16,14 @@ This rule is enabled by default. ### Default configuration -The following pattern is considered warning: +The following patterns are considered warnings: ```js expect(null).toBe(null); + +expect(null).isEqual(null); + +expect(null).toStrictEqual(null); ``` The following pattern is not warning: diff --git a/docs/rules/prefer-to-be-undefined.md b/docs/rules/prefer-to-be-undefined.md index ac9a98f5a..57b4442e3 100644 --- a/docs/rules/prefer-to-be-undefined.md +++ b/docs/rules/prefer-to-be-undefined.md @@ -5,7 +5,8 @@ asserting expections on undefined value. ## Rule details -This rule triggers a warning if `toBe()` is used to assert a undefined value. +This rule triggers a warning if `toBe()`, `isEqual()` or `toStrictEqual()` is +used to assert an undefined value. ```js expect(undefined).toBe(undefined); @@ -15,10 +16,14 @@ This rule is enabled by default. ### Default configuration -The following pattern is considered warning: +The following patterns are considered warnings: ```js expect(undefined).toBe(undefined); + +expect(undefined).isEqual(undefined); + +expect(undefined).toStrictEqual(undefined); ``` The following pattern is not warning: diff --git a/docs/rules/prefer-to-contain.md b/docs/rules/prefer-to-contain.md index 3014967dc..b58452ee1 100644 --- a/docs/rules/prefer-to-contain.md +++ b/docs/rules/prefer-to-contain.md @@ -5,8 +5,8 @@ asserting expectations on an array containing an object. ## Rule details -This rule triggers a warning if `toBe()` or `isEqual()` is used to assert object -inclusion in an array +This rule triggers a warning if `toBe()`, `isEqual()` or `toStrictEqual()` is +used to assert object inclusion in an array ```js expect(a.includes(b)).toBe(true); @@ -22,26 +22,24 @@ expect(a.includes(b)).toBe(false); ### Default configuration -The following patterns are considered a warning: +The following patterns are considered warnings: ```js expect(a.includes(b)).toBe(true); -``` -```js expect(a.includes(b)).not.toBe(true); -``` -```js expect(a.includes(b)).toBe(false); + +expect(a.includes(b)).toEqual(true); + +expect(a.includes(b)).toStrictEqual(true); ``` -The following patterns are not a warning: +The following patterns are not considered warnings: ```js expect(a).toContain(b); -``` -```js expect(a).not.toContain(b); ``` diff --git a/docs/rules/prefer-to-have-length.md b/docs/rules/prefer-to-have-length.md index bf75ef253..1a74387b0 100644 --- a/docs/rules/prefer-to-have-length.md +++ b/docs/rules/prefer-to-have-length.md @@ -5,8 +5,8 @@ asserting expectations on object's length property. ## Rule details -This rule triggers a warning if `toBe()` is used to assert object's length -property. +This rule triggers a warning if `toBe()`, `isEqual()` or `toStrictEqual()` is +used to assert object's length property. ```js expect(files.length).toBe(1); @@ -16,10 +16,14 @@ This rule is enabled by default. ### Default configuration -The following pattern is considered warning: +The following patterns are considered warnings: ```js expect(files.length).toBe(1); + +expect(files.length).toEqual(1); + +expect(files.length).toStrictEqual(1); ``` The following pattern is not warning: diff --git a/src/rules/__tests__/prefer-to-be-null.test.ts b/src/rules/__tests__/prefer-to-be-null.test.ts index 212f9e50c..cbf6ee242 100644 --- a/src/rules/__tests__/prefer-to-be-null.test.ts +++ b/src/rules/__tests__/prefer-to-be-null.test.ts @@ -31,6 +31,11 @@ ruleTester.run('prefer-to-be-null', rule, { errors: [{ messageId: 'useToBeNull', column: 14, line: 1 }], output: 'expect(null).toBeNull();', }, + { + code: 'expect(null).toStrictEqual(null);', + errors: [{ messageId: 'useToBeNull', column: 14, line: 1 }], + output: 'expect(null).toBeNull();', + }, { code: 'expect("a string").not.toBe(null);', errors: [{ messageId: 'useToBeNull', column: 24, line: 1 }], @@ -41,6 +46,11 @@ ruleTester.run('prefer-to-be-null', rule, { errors: [{ messageId: 'useToBeNull', column: 24, line: 1 }], output: 'expect("a string").not.toBeNull();', }, + { + code: 'expect("a string").not.toStrictEqual(null);', + errors: [{ messageId: 'useToBeNull', column: 24, line: 1 }], + output: 'expect("a string").not.toBeNull();', + }, ], }); diff --git a/src/rules/__tests__/prefer-to-be-undefined.test.ts b/src/rules/__tests__/prefer-to-be-undefined.test.ts index c07a30cd6..6f4911a9d 100644 --- a/src/rules/__tests__/prefer-to-be-undefined.test.ts +++ b/src/rules/__tests__/prefer-to-be-undefined.test.ts @@ -29,6 +29,11 @@ ruleTester.run('prefer-to-be-undefined', rule, { errors: [{ messageId: 'useToBeUndefined', column: 19, line: 1 }], output: 'expect(undefined).toBeUndefined();', }, + { + code: 'expect(undefined).toStrictEqual(undefined);', + errors: [{ messageId: 'useToBeUndefined', column: 19, line: 1 }], + output: 'expect(undefined).toBeUndefined();', + }, { code: 'expect("a string").not.toBe(undefined);', errors: [{ messageId: 'useToBeUndefined', column: 24, line: 1 }], @@ -39,6 +44,11 @@ ruleTester.run('prefer-to-be-undefined', rule, { errors: [{ messageId: 'useToBeUndefined', column: 24, line: 1 }], output: 'expect("a string").not.toBeUndefined();', }, + { + code: 'expect("a string").not.toStrictEqual(undefined);', + errors: [{ messageId: 'useToBeUndefined', column: 24, line: 1 }], + output: 'expect("a string").not.toBeUndefined();', + }, ], }); diff --git a/src/rules/__tests__/prefer-to-contain.test.ts b/src/rules/__tests__/prefer-to-contain.test.ts index 588a2d309..d3e0856af 100644 --- a/src/rules/__tests__/prefer-to-contain.test.ts +++ b/src/rules/__tests__/prefer-to-contain.test.ts @@ -72,6 +72,26 @@ ruleTester.run('prefer-to-contain', rule, { errors: [{ messageId: 'useToContain', column: 23, line: 1 }], output: 'expect(a).not.toContain(b);', }, + { + code: 'expect(a.includes(b)).toStrictEqual(true);', + errors: [{ messageId: 'useToContain', column: 23, line: 1 }], + output: 'expect(a).toContain(b);', + }, + { + code: 'expect(a.includes(b)).toStrictEqual(false);', + errors: [{ messageId: 'useToContain', column: 23, line: 1 }], + output: 'expect(a).not.toContain(b);', + }, + { + code: 'expect(a.includes(b)).not.toStrictEqual(false);', + errors: [{ messageId: 'useToContain', column: 23, line: 1 }], + output: 'expect(a).toContain(b);', + }, + { + code: 'expect(a.includes(b)).not.toStrictEqual(true);', + errors: [{ messageId: 'useToContain', column: 23, line: 1 }], + output: 'expect(a).not.toContain(b);', + }, { code: 'expect(a.test(t).includes(b.test(p))).toEqual(true);', errors: [{ messageId: 'useToContain', column: 39, line: 1 }], @@ -112,6 +132,26 @@ ruleTester.run('prefer-to-contain', rule, { errors: [{ messageId: 'useToContain', column: 33, line: 1 }], output: 'expect([{a:1}]).toContain({a:1});', }, + { + code: 'expect([{a:1}].includes({a:1})).toStrictEqual(true);', + errors: [{ messageId: 'useToContain', column: 33, line: 1 }], + output: 'expect([{a:1}]).toContain({a:1});', + }, + { + code: 'expect([{a:1}].includes({a:1})).toStrictEqual(false);', + errors: [{ messageId: 'useToContain', column: 33, line: 1 }], + output: 'expect([{a:1}]).not.toContain({a:1});', + }, + { + code: 'expect([{a:1}].includes({a:1})).not.toStrictEqual(true);', + errors: [{ messageId: 'useToContain', column: 33, line: 1 }], + output: 'expect([{a:1}]).not.toContain({a:1});', + }, + { + code: 'expect([{a:1}].includes({a:1})).not.toStrictEqual(false);', + errors: [{ messageId: 'useToContain', column: 33, line: 1 }], + output: 'expect([{a:1}]).toContain({a:1});', + }, ], }); diff --git a/src/rules/__tests__/prefer-to-have-length.test.ts b/src/rules/__tests__/prefer-to-have-length.test.ts index e3ec820cc..d4864fc98 100644 --- a/src/rules/__tests__/prefer-to-have-length.test.ts +++ b/src/rules/__tests__/prefer-to-have-length.test.ts @@ -36,5 +36,10 @@ ruleTester.run('prefer-to-have-length', rule, { errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }], output: 'expect(files).toHaveLength(1);', }, + { + code: 'expect(files.length).toStrictEqual(1);', + errors: [{ messageId: 'useToHaveLength', column: 22, line: 1 }], + output: 'expect(files).toHaveLength(1);', + }, ], }); diff --git a/src/rules/utils.ts b/src/rules/utils.ts index 57ff0e4f7..45390171f 100644 --- a/src/rules/utils.ts +++ b/src/rules/utils.ts @@ -341,6 +341,7 @@ export enum ModifierName { enum EqualityMatcher { toBe = 'toBe', toEqual = 'toEqual', + toStrictEqual = 'toStrictEqual', } export const isParsedEqualityMatcherCall = (