diff --git a/README.md b/README.md index 68a8192ef..e511b73e9 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,6 @@ installations requiring long-term consistency. | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | | ![fixable][] | | [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended][] | | | [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | | -| [no-expect-resolves](docs/rules/no-expect-resolves.md) | Disallow expect.resolves | | | | [no-export](docs/rules/no-export.md) | Prevent exporting from test files | ![recommended][] | | | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![fixable][] | | [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | | @@ -152,12 +151,10 @@ 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()` | | | | [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest to have all hooks at top level | | | -| [prefer-inline-snapshots](docs/rules/prefer-inline-snapshots.md) | Suggest using inline snapshots | | ![fixable][] | | [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | ![fixable][] | | [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using toStrictEqual() | | ![fixable][] | | [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using `toBeNull()` | ![style][] | ![fixable][] | diff --git a/docs/rules/no-expect-resolves.md b/docs/rules/no-expect-resolves.md index 59510f5fb..31cb51f43 100644 --- a/docs/rules/no-expect-resolves.md +++ b/docs/rules/no-expect-resolves.md @@ -1,5 +1,23 @@ # Avoid using `expect().resolves` (`no-expect-resolves`) +## 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", + { "resolves": "Use `expect(await promise)` instead." } + ] + } +} +``` + +--- + Jest allows you to test a promise resolve value using `await expect().resolves`. For consistency and readability this rule bans `expect().resolves` in favor of `expect(await promise)`. 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/docs/rules/prefer-inline-snapshots.md b/docs/rules/prefer-inline-snapshots.md index 7922eb5bc..f6c5998cf 100644 --- a/docs/rules/prefer-inline-snapshots.md +++ b/docs/rules/prefer-inline-snapshots.md @@ -1,5 +1,26 @@ # Suggest using inline snapshots (`prefer-inline-snapshots`) +## 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", + { + "toThrowErrorMatchingSnapshot": "Use `toThrowErrorMatchingInlineSnapshot()` instead", + "toMatchSnapshot": "Use `toMatchInlineSnapshot()` instead" + } + ] + } +} +``` + +--- + In order to make snapshot tests more managable and reviewable `toMatchInlineSnapshot()` and `toThrowErrorMatchingInlineSnapshot` should be used to write the snapshots inline in the test file. diff --git a/src/rules/no-expect-resolves.ts b/src/rules/no-expect-resolves.ts index 7ad0e0613..654e3cf8d 100644 --- a/src/rules/no-expect-resolves.ts +++ b/src/rules/no-expect-resolves.ts @@ -13,6 +13,8 @@ export default createRule({ description: 'Disallow expect.resolves', recommended: false, }, + deprecated: true, + replacedBy: ['no-restricted-matchers'], messages: { expectResolves: 'Use `expect(await promise)` instead.', }, 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 }}', }, diff --git a/src/rules/prefer-inline-snapshots.ts b/src/rules/prefer-inline-snapshots.ts index e00d3e81a..55cb3af21 100644 --- a/src/rules/prefer-inline-snapshots.ts +++ b/src/rules/prefer-inline-snapshots.ts @@ -9,6 +9,8 @@ export default createRule({ description: 'Suggest using inline snapshots', recommended: false, }, + deprecated: true, + replacedBy: ['no-restricted-matchers'], messages: { toMatch: 'Use toMatchInlineSnapshot() instead', toMatchError: 'Use toThrowErrorMatchingInlineSnapshot() instead',