From 1360e9b0e840f4f778a9d251371c943919f84600 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 16 May 2020 13:27:25 +1200 Subject: [PATCH] feat: deprecate `prefer-inline-snapshots` rule --- README.md | 1 - docs/rules/prefer-inline-snapshots.md | 21 +++++++++++++++++++++ src/rules/prefer-inline-snapshots.ts | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 553da29a6..e511b73e9 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,6 @@ installations requiring long-term consistency. | [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/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/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',