From 914b24a0bc12a151e6f7ecec37a440769b555b94 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 28 Aug 2022 21:48:07 +1200 Subject: [PATCH] feat: make `no-alias-methods` recommended (#1221) BREAKING CHANGE: `no-alias-methods` is now recommended as the methods themselves will be removed in the next major version of Jest --- README.md | 2 +- docs/rules/no-alias-methods.md | 3 +++ src/__tests__/__snapshots__/rules.test.ts.snap | 1 + src/rules/no-alias-methods.ts | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d55d31676..3c912c6af 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ installations requiring long-term consistency. | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | ![recommended][] | | | [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | | | [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | | -| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![style][] | ![fixable][] | +| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![recommended][] | ![fixable][] | | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | | | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | | | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | | diff --git a/docs/rules/no-alias-methods.md b/docs/rules/no-alias-methods.md index 7f373d5fe..d439104de 100644 --- a/docs/rules/no-alias-methods.md +++ b/docs/rules/no-alias-methods.md @@ -1,5 +1,8 @@ # Disallow alias methods (`no-alias-methods`) +> These aliases are going to be removed in the next major version of Jest - see +> https://github.com/facebook/jest/issues/13164 for more + Several Jest methods have alias names, such as `toThrow` having the alias of `toThrowError`. This rule ensures that only the canonical name as used in the Jest documentation is used in the code. This makes it easier to search for all diff --git a/src/__tests__/__snapshots__/rules.test.ts.snap b/src/__tests__/__snapshots__/rules.test.ts.snap index 9932b994d..620da645c 100644 --- a/src/__tests__/__snapshots__/rules.test.ts.snap +++ b/src/__tests__/__snapshots__/rules.test.ts.snap @@ -69,6 +69,7 @@ exports[`rules should export configs that refer to actual rules 1`] = ` ], "rules": { "jest/expect-expect": "warn", + "jest/no-alias-methods": "error", "jest/no-commented-out-tests": "warn", "jest/no-conditional-expect": "error", "jest/no-deprecated-functions": "error", diff --git a/src/rules/no-alias-methods.ts b/src/rules/no-alias-methods.ts index 814b73f5c..dfd4a9629 100644 --- a/src/rules/no-alias-methods.ts +++ b/src/rules/no-alias-methods.ts @@ -11,7 +11,7 @@ export default createRule({ docs: { category: 'Best Practices', description: 'Disallow alias methods', - recommended: false, + recommended: 'error', }, messages: { replaceAlias: `Replace {{ alias }}() with its canonical name of {{ canonical }}()`,