Skip to content

Commit 8bfb1de

Browse files
committed
docs: consistent rule doc notices and sections
1 parent 954a0e6 commit 8bfb1de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+379
-31
lines changed

docs/rules/consistent-test-it.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
# Have control over `test` and `it` usages (`consistent-test-it`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
6+
<!-- prettier-ignore -->
7+
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
8+
39
Jest allows you to choose how you want to define your tests, using the `it` or
410
the `test` keywords, with multiple permutations for each:
511

612
- **it:** `it`, `xit`, `fit`, `it.only`, `it.skip`.
713
- **test:** `test`, `xtest`, `test.only`, `test.skip`.
814

15+
## Rule Details
16+
917
This rule gives you control over the usage of these keywords in your codebase.
1018

11-
## Rule Details
19+
## Options
1220

1321
This rule can be configured as follows
1422

docs/rules/expect-expect.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Enforce assertion to be made in a test body (`expect-expect`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
Ensure that there is at least one `expect` call made in a test.
47

5-
## Rule details
8+
## Rule Details
69

710
This rule triggers when there is no call made to `expect` in a test, to prevent
811
users from forgetting to add assertions.

docs/rules/max-expects.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Enforces a maximum number assertion calls in a test body (`max-expects`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
As more assertions are made, there is a possible tendency for the test to be
47
more likely to mix multiple objectives. To avoid this, this rule reports when
58
the maximum number of assertions is exceeded.

docs/rules/max-nested-describe.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Enforces a maximum depth to nested describe calls (`max-nested-describe`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
While it's useful to be able to group your tests together within the same file
47
using `describe()`, having too many levels of nesting throughout your tests make
58
them difficult to read.

docs/rules/no-alias-methods.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Disallow alias methods (`no-alias-methods`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
6+
<!-- prettier-ignore -->
7+
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
8+
39
> These aliases are going to be removed in the next major version of Jest - see
410
> https://github.com/facebook/jest/issues/13164 for more
511
@@ -9,7 +15,7 @@ Jest documentation is used in the code. This makes it easier to search for all
915
occurrences of the method within code, and it ensures consistency among the
1016
method names used.
1117

12-
## Rule details
18+
## Rule Details
1319

1420
This rule triggers a warning if the alias name, rather than the canonical name,
1521
of a method is used.

docs/rules/no-commented-out-tests.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow commented out tests (`no-commented-out-tests`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
This rule raises a warning about commented out tests. It's similar to
47
no-disabled-tests rule.
58

docs/rules/no-conditional-expect.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Prevent calling `expect` conditionally (`no-conditional-expect`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
36
This rule prevents the use of `expect` in conditional blocks, such as `if`s &
47
`catch`s.
58

docs/rules/no-conditional-in-test.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow conditional logic in tests (`no-conditional-in-test`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
Conditional logic in tests is usually an indication that a test is attempting to
47
cover too much, and not testing the logic it intends to. Each branch of code
58
executing within a conditional statement will usually be better served by a test

docs/rules/no-deprecated-functions.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Disallow use of deprecated functions (`no-deprecated-functions`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
6+
<!-- prettier-ignore -->
7+
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
8+
39
Over the years Jest has accrued some debt in the form of functions that have
410
either been renamed for clarity, or replaced with more powerful APIs.
511

@@ -11,7 +17,7 @@ This rule requires knowing which version of Jest you're using - see
1117
on how that is obtained automatically and how you can explicitly provide a
1218
version if needed.
1319

14-
## Rule details
20+
## Rule Details
1521

1622
This rule warns about calls to deprecated functions, and provides details on
1723
what to replace them with, based on the version of Jest that is installed.

docs/rules/no-disabled-tests.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow disabled tests (`no-disabled-tests`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
Jest has a feature that allows you to temporarily mark tests as disabled. This
47
feature is often helpful while debugging or to create placeholders for future
58
tests. Before committing changes we may want to check that all tests are

docs/rules/no-done-callback.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
6+
<!-- prettier-ignore -->
7+
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
8+
39
When calling asynchronous code in hooks and tests, `jest` needs to know when the
410
asynchronous work is complete to progress the current run.
511

@@ -49,7 +55,7 @@ test('the data is peanut butter', async () => {
4955
});
5056
```
5157

52-
## Rule details
58+
## Rule Details
5359

5460
This rule checks the function parameter of hooks & tests for use of the `done`
5561
argument, suggesting you return a promise instead.

docs/rules/no-duplicate-hooks.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
A `describe` block should not contain duplicate hooks.
47

58
## Rule Details

docs/rules/no-export.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow using `exports` in files containing tests (`no-export`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
36
Prevents using `exports` if a file has one or more tests in it.
47

58
## Rule Details

docs/rules/no-focused-tests.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Disallow focused tests (`no-focused-tests`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
6+
<!-- prettier-ignore -->
7+
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
8+
39
Jest has a feature that allows you to focus tests by appending `.only` or
410
prepending `f` to a test-suite or a test-case. This feature is really helpful to
511
debug a failing test, so you don’t have to execute all of your tests. After you

docs/rules/no-hooks.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow setup and teardown hooks (`no-hooks`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
Jest provides global functions for setup and teardown tasks, which are called
47
before/after each test case and each test suite. The use of these hooks promotes
58
shared state between tests.

docs/rules/no-identical-title.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow identical titles (`no-identical-title`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
36
Having identical titles for two different tests or test suites may create
47
confusion. For example, when a test with the same title as another test in the
58
same test suite fails, it is harder to know which one failed and thus harder to

docs/rules/no-if.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow conditional logic (`no-if`)
22

3-
## Deprecated
3+
❌ This rule is deprecated.
44

55
This rule has been deprecated in favor of
66
[`no-conditional-in-test`](no-conditional-in-test.md).

docs/rules/no-interpolation-in-snapshots.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
36
Prevents the use of string interpolations in snapshots.
47

58
## Rule Details

docs/rules/no-jasmine-globals.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Disallow Jasmine globals (`no-jasmine-globals`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
6+
<!-- prettier-ignore -->
7+
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
8+
39
`jest` uses `jasmine` as a test runner. A side effect of this is that both a
410
`jasmine` object, and some jasmine-specific globals, are exposed to the test
511
environment. Most functionality offered by Jasmine has been ported to Jest, and
612
the Jasmine globals will stop working in the future. Developers should therefore
713
migrate to Jest's documented API instead of relying on the undocumented Jasmine
814
API.
915

10-
### Rule details
16+
## Rule Details
1117

1218
This rule reports on any usage of Jasmine globals, which is not ported to Jest,
1319
and suggests alternatives from Jest's own API.

docs/rules/no-large-snapshots.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# disallow large snapshots (`no-large-snapshots`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
When using Jest's snapshot capability one should be mindful of the size of
47
created snapshots. As a general best practice snapshots should be limited in
58
size in order to be more manageable and reviewable. A stored snapshot is only as

docs/rules/no-mocks-import.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow manually importing from `__mocks__` (`no-mocks-import`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
36
When using `jest.mock`, your tests (just like the code being tested) should
47
import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
58
confusion, because you will have multiple instances of the mocked module:
@@ -14,7 +17,7 @@ test('x', () => {
1417
});
1518
```
1619

17-
### Rule details
20+
## Rule Details
1821

1922
This rule reports imports from a path containing a `__mocks__` component.
2023

docs/rules/no-restricted-matchers.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# Disallow specific matchers & modifiers (`no-restricted-matchers`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
6+
You may want to ban specific matchers & modifiers from being used.
7+
8+
## Rule Details
9+
310
This rule bans specific matchers & modifiers from being used, and can suggest
411
alternatives.
512

6-
## Rule Details
13+
## Options
714

815
Bans are expressed in the form of a map, with the value being either a string
916
message to be shown, or `null` if the default rule message should be used.

docs/rules/no-standalone-expect.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Disallow using `expect` outside of `it` or `test` blocks (`no-standalone-expect`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
36
Prevents `expect` statements outside of a `test` or `it` block. An `expect`
47
within a helper function (but outside of a `test` or `it` block) will not
58
trigger this rule.

docs/rules/no-test-prefixes.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Use `.only` and `.skip` over `f` and `x` (`no-test-prefixes`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.
5+
6+
<!-- prettier-ignore -->
7+
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
8+
39
Jest allows you to choose how you want to define focused and skipped tests, with
410
multiple permutations for each:
511

@@ -9,7 +15,7 @@ multiple permutations for each:
915

1016
This rule enforces usages from the **only & skip** list.
1117

12-
## Rule details
18+
## Rule Details
1319

1420
This rule triggers a warning if you use one of the keywords from the **'f' &
1521
'x'** list to focus/skip a test.

docs/rules/no-test-return-statement.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Disallow explicitly returning from tests (`no-test-return-statement`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
Tests in Jest should be void and not return values.
47

58
If you are returning Promises then you should update the test to use
69
`async/await`.
710

8-
## Rule details
11+
## Rule Details
912

1013
This rule triggers a warning if you use a return statement inside a test body.
1114

docs/rules/prefer-called-with.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`prefer-called-with`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
The `toBeCalled()` matcher is used to assert that a mock function has been
47
called one or more times, without checking the arguments passed. The assertion
58
is stronger when arguments are also validated using the `toBeCalledWith()`
@@ -9,7 +12,7 @@ matcher. When some arguments are difficult to check, using generic match like
912
This rule warns if the form without argument checking is used, except for `.not`
1013
enforcing a function has never been called.
1114

12-
## Rule details
15+
## Rule Details
1316

1417
The following patterns are warnings:
1518

docs/rules/prefer-comparison-matcher.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
6+
<!-- prettier-ignore -->
7+
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
8+
39
Jest has a number of built-in matchers for comparing numbers, which allow for
410
more readable tests and error messages if an expectation fails.
511

6-
## Rule details
12+
## Rule Details
713

814
This rule checks for comparisons in tests that could be replaced with one of the
915
following built-in comparison matchers:

docs/rules/prefer-each.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Prefer using `.each` rather than manual loops (`prefer-each`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
36
Reports where you might be able to use `.each` instead of native loops.
47

5-
## Rule details
8+
## Rule Details
69

710
This rule triggers a warning if you use test case functions like `describe`,
811
`test`, and `it`, in a native loop - generally you should be able to use `.each`

docs/rules/prefer-equality-matcher.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Suggest using the built-in equality matchers (`prefer-equality-matcher`)
22

3+
<!-- prettier-ignore -->
4+
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.
5+
6+
<!-- prettier-ignore -->
7+
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
8+
39
Jest has built-in matchers for expecting equality, which allow for more readable
410
tests and error messages if an expectation fails.
511

6-
## Rule details
12+
## Rule Details
713

814
This rule checks for _strict_ equality checks (`===` & `!==`) in tests that
915
could be replaced with one of the following built-in equality matchers:

0 commit comments

Comments
 (0)