Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate rules #583

Merged
merged 3 commits into from May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Expand Up @@ -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 | | |
Expand All @@ -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][] |
Expand Down
18 changes: 18 additions & 0 deletions 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)`.
Expand Down
21 changes: 21 additions & 0 deletions 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.

Expand Down
21 changes: 21 additions & 0 deletions 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.
Expand Down
2 changes: 2 additions & 0 deletions src/rules/no-expect-resolves.ts
Expand Up @@ -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.',
},
Expand Down
2 changes: 2 additions & 0 deletions src/rules/no-truthy-falsy.ts
Expand Up @@ -9,6 +9,8 @@ export default createRule({
description: 'Disallow using `toBeTruthy()` & `toBeFalsy()`',
recommended: false,
},
deprecated: true,
replacedBy: ['no-restricted-matchers'],
messages: {
avoidMatcher: 'Avoid {{ matcherName }}',
},
Expand Down
2 changes: 2 additions & 0 deletions src/rules/prefer-inline-snapshots.ts
Expand Up @@ -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',
Expand Down