diff --git a/README.md b/README.md index 73198d090..553da29a6 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,6 @@ installations requiring long-term consistency. | [no-test-callback](docs/rules/no-test-callback.md) | Avoid using a callback in asynchronous tests | ![recommended][] | ![fixable][] | | [no-test-prefixes](docs/rules/no-test-prefixes.md) | Use `.only` and `.skip` over `f` and `x` | ![recommended][] | ![fixable][] | | [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | | -| [no-truthy-falsy](docs/rules/no-truthy-falsy.md) | Disallow using `toBeTruthy()` & `toBeFalsy()` | | | | [no-try-expect](docs/rules/no-try-expect.md) | Prefer using toThrow for exception tests | ![recommended][] | | | [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` OR `toHaveBeenCalledWith()` | | | | [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | | diff --git a/docs/rules/no-truthy-falsy.md b/docs/rules/no-truthy-falsy.md index 06d56208c..aa23b1fc7 100644 --- a/docs/rules/no-truthy-falsy.md +++ b/docs/rules/no-truthy-falsy.md @@ -1,5 +1,26 @@ # Disallow using `toBeTruthy()` & `toBeFalsy()` (`no-truthy-falsy`) +## Deprecated + +This rule has been deprecated in favor of +[`no-restricted-matchers`](no-restricted-matchers.md) with the following config: + +```json +{ + "rules": { + "jest/no-restricted-matchers": [ + "error", + { + "toBeTruthy": "Avoid `toBeTruthy`", + "toBeFalsy": "Avoid `toBeFalsy`" + } + ] + } +} +``` + +--- + Tests against boolean values should assert true or false. Asserting `toBeTruthy` or `toBeFalsy` matches non-boolean values as well and encourages weaker tests. diff --git a/src/rules/no-truthy-falsy.ts b/src/rules/no-truthy-falsy.ts index a3cc2d5b9..dfdd4998b 100644 --- a/src/rules/no-truthy-falsy.ts +++ b/src/rules/no-truthy-falsy.ts @@ -9,6 +9,8 @@ export default createRule({ description: 'Disallow using `toBeTruthy()` & `toBeFalsy()`', recommended: false, }, + deprecated: true, + replacedBy: ['no-restricted-matchers'], messages: { avoidMatcher: 'Avoid {{ matcherName }}', },