Skip to content

Commit

Permalink
docs: consistent rule doc notices and sections
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Aug 28, 2022
1 parent 954a0e6 commit bf22c94
Show file tree
Hide file tree
Showing 51 changed files with 381 additions and 31 deletions.
10 changes: 9 additions & 1 deletion docs/rules/consistent-test-it.md
@@ -1,14 +1,22 @@
# Have control over `test` and `it` usages (`consistent-test-it`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

Jest allows you to choose how you want to define your tests, using the `it` or
the `test` keywords, with multiple permutations for each:

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

## Rule Details

This rule gives you control over the usage of these keywords in your codebase.

## Rule Details
## Options

This rule can be configured as follows

Expand Down
5 changes: 4 additions & 1 deletion docs/rules/expect-expect.md
@@ -1,8 +1,11 @@
# Enforce assertion to be made in a test body (`expect-expect`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

Ensure that there is at least one `expect` call made in a test.

## Rule details
## Rule Details

This rule triggers when there is no call made to `expect` in a test, to prevent
users from forgetting to add assertions.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/max-expects.md
@@ -1,5 +1,8 @@
# Enforces a maximum number assertion calls in a test body (`max-expects`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

As more assertions are made, there is a possible tendency for the test to be
more likely to mix multiple objectives. To avoid this, this rule reports when
the maximum number of assertions is exceeded.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/max-nested-describe.md
@@ -1,5 +1,8 @@
# Enforces a maximum depth to nested describe calls (`max-nested-describe`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

While it's useful to be able to group your tests together within the same file
using `describe()`, having too many levels of nesting throughout your tests make
them difficult to read.
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/no-alias-methods.md
@@ -1,5 +1,11 @@
# Disallow alias methods (`no-alias-methods`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

> These aliases are going to be removed in the next major version of Jest - see
> https://github.com/facebook/jest/issues/13164 for more
Expand All @@ -9,7 +15,7 @@ Jest documentation is used in the code. This makes it easier to search for all
occurrences of the method within code, and it ensures consistency among the
method names used.

## Rule details
## Rule Details

This rule triggers a warning if the alias name, rather than the canonical name,
of a method is used.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-commented-out-tests.md
@@ -1,5 +1,8 @@
# Disallow commented out tests (`no-commented-out-tests`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

This rule raises a warning about commented out tests. It's similar to
no-disabled-tests rule.

Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-conditional-expect.md
@@ -1,5 +1,8 @@
# Prevent calling `expect` conditionally (`no-conditional-expect`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

This rule prevents the use of `expect` in conditional blocks, such as `if`s &
`catch`s.

Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-conditional-in-test.md
@@ -1,5 +1,8 @@
# Disallow conditional logic in tests (`no-conditional-in-test`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

Conditional logic in tests is usually an indication that a test is attempting to
cover too much, and not testing the logic it intends to. Each branch of code
executing within a conditional statement will usually be better served by a test
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/no-deprecated-functions.md
@@ -1,5 +1,11 @@
# Disallow use of deprecated functions (`no-deprecated-functions`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

Over the years Jest has accrued some debt in the form of functions that have
either been renamed for clarity, or replaced with more powerful APIs.

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

## Rule details
## Rule Details

This rule warns about calls to deprecated functions, and provides details on
what to replace them with, based on the version of Jest that is installed.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-disabled-tests.md
@@ -1,5 +1,8 @@
# Disallow disabled tests (`no-disabled-tests`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

Jest has a feature that allows you to temporarily mark tests as disabled. This
feature is often helpful while debugging or to create placeholders for future
tests. Before committing changes we may want to check that all tests are
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/no-done-callback.md
@@ -1,5 +1,11 @@
# Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).

When calling asynchronous code in hooks and tests, `jest` needs to know when the
asynchronous work is complete to progress the current run.

Expand Down Expand Up @@ -49,7 +55,7 @@ test('the data is peanut butter', async () => {
});
```

## Rule details
## Rule Details

This rule checks the function parameter of hooks & tests for use of the `done`
argument, suggesting you return a promise instead.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-duplicate-hooks.md
@@ -1,5 +1,8 @@
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

A `describe` block should not contain duplicate hooks.

## Rule Details
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-export.md
@@ -1,5 +1,8 @@
# Disallow using `exports` in files containing tests (`no-export`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

Prevents using `exports` if a file has one or more tests in it.

## Rule Details
Expand Down
6 changes: 6 additions & 0 deletions docs/rules/no-focused-tests.md
@@ -1,5 +1,11 @@
# Disallow focused tests (`no-focused-tests`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).

Jest has a feature that allows you to focus tests by appending `.only` or
prepending `f` to a test-suite or a test-case. This feature is really helpful to
debug a failing test, so you don’t have to execute all of your tests. After you
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-hooks.md
@@ -1,5 +1,8 @@
# Disallow setup and teardown hooks (`no-hooks`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

Jest provides global functions for setup and teardown tasks, which are called
before/after each test case and each test suite. The use of these hooks promotes
shared state between tests.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-identical-title.md
@@ -1,5 +1,8 @@
# Disallow identical titles (`no-identical-title`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

Having identical titles for two different tests or test suites may create
confusion. For example, when a test with the same title as another test in the
same test suite fails, it is harder to know which one failed and thus harder to
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-if.md
@@ -1,6 +1,6 @@
# Disallow conditional logic (`no-if`)

## Deprecated
❌ This rule is deprecated.

This rule has been deprecated in favor of
[`no-conditional-in-test`](no-conditional-in-test.md).
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-interpolation-in-snapshots.md
@@ -1,5 +1,8 @@
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

Prevents the use of string interpolations in snapshots.

## Rule Details
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/no-jasmine-globals.md
@@ -1,13 +1,19 @@
# Disallow Jasmine globals (`no-jasmine-globals`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

`jest` uses `jasmine` as a test runner. A side effect of this is that both a
`jasmine` object, and some jasmine-specific globals, are exposed to the test
environment. Most functionality offered by Jasmine has been ported to Jest, and
the Jasmine globals will stop working in the future. Developers should therefore
migrate to Jest's documented API instead of relying on the undocumented Jasmine
API.

### Rule details
## Rule Details

This rule reports on any usage of Jasmine globals, which is not ported to Jest,
and suggests alternatives from Jest's own API.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-large-snapshots.md
@@ -1,5 +1,8 @@
# disallow large snapshots (`no-large-snapshots`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

When using Jest's snapshot capability one should be mindful of the size of
created snapshots. As a general best practice snapshots should be limited in
size in order to be more manageable and reviewable. A stored snapshot is only as
Expand Down
5 changes: 4 additions & 1 deletion docs/rules/no-mocks-import.md
@@ -1,5 +1,8 @@
# Disallow manually importing from `__mocks__` (`no-mocks-import`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

When using `jest.mock`, your tests (just like the code being tested) should
import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
confusion, because you will have multiple instances of the mocked module:
Expand All @@ -14,7 +17,7 @@ test('x', () => {
});
```

### Rule details
## Rule Details

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

Expand Down
9 changes: 8 additions & 1 deletion docs/rules/no-restricted-matchers.md
@@ -1,9 +1,16 @@
# Disallow specific matchers & modifiers (`no-restricted-matchers`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

You may want to ban specific matchers & modifiers from being used.

## Rule Details

This rule bans specific matchers & modifiers from being used, and can suggest
alternatives.

## Rule Details
## Options

Bans are expressed in the form of a map, with the value being either a string
message to be shown, or `null` if the default rule message should be used.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-standalone-expect.md
@@ -1,5 +1,8 @@
# Disallow using `expect` outside of `it` or `test` blocks (`no-standalone-expect`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

Prevents `expect` statements outside of a `test` or `it` block. An `expect`
within a helper function (but outside of a `test` or `it` block) will not
trigger this rule.
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/no-test-prefixes.md
@@ -1,5 +1,11 @@
# Use `.only` and `.skip` over `f` and `x` (`no-test-prefixes`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

Jest allows you to choose how you want to define focused and skipped tests, with
multiple permutations for each:

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

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

## Rule details
## Rule Details

This rule triggers a warning if you use one of the keywords from the **'f' &
'x'** list to focus/skip a test.
Expand Down
5 changes: 4 additions & 1 deletion docs/rules/no-test-return-statement.md
@@ -1,11 +1,14 @@
# Disallow explicitly returning from tests (`no-test-return-statement`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

Tests in Jest should be void and not return values.

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

## Rule details
## Rule Details

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

Expand Down
5 changes: 4 additions & 1 deletion docs/rules/prefer-called-with.md
@@ -1,5 +1,8 @@
# Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`prefer-called-with`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

The `toBeCalled()` matcher is used to assert that a mock function has been
called one or more times, without checking the arguments passed. The assertion
is stronger when arguments are also validated using the `toBeCalledWith()`
Expand All @@ -9,7 +12,7 @@ matcher. When some arguments are difficult to check, using generic match like
This rule warns if the form without argument checking is used, except for `.not`
enforcing a function has never been called.

## Rule details
## Rule Details

The following patterns are warnings:

Expand Down
8 changes: 7 additions & 1 deletion docs/rules/prefer-comparison-matcher.md
@@ -1,9 +1,15 @@
# Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

Jest has a number of built-in matchers for comparing numbers, which allow for
more readable tests and error messages if an expectation fails.

## Rule details
## Rule Details

This rule checks for comparisons in tests that could be replaced with one of the
following built-in comparison matchers:
Expand Down
5 changes: 4 additions & 1 deletion docs/rules/prefer-each.md
@@ -1,8 +1,11 @@
# Prefer using `.each` rather than manual loops (`prefer-each`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

Reports where you might be able to use `.each` instead of native loops.

## Rule details
## Rule Details

This rule triggers a warning if you use test case functions like `describe`,
`test`, and `it`, in a native loop - generally you should be able to use `.each`
Expand Down
8 changes: 7 additions & 1 deletion docs/rules/prefer-equality-matcher.md
@@ -1,9 +1,15 @@
# Suggest using the built-in equality matchers (`prefer-equality-matcher`)

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- prettier-ignore -->
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).

Jest has built-in matchers for expecting equality, which allow for more readable
tests and error messages if an expectation fails.

## Rule details
## Rule Details

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

0 comments on commit bf22c94

Please sign in to comment.