github-pages-deploy-action/node_modules/eslint-plugin-jest/docs/rules/lowercase-name.md

107 lines
2.3 KiB
Markdown
Raw Normal View History

2020-05-15 05:33:08 +08:00
# Enforce lowercase test names (`lowercase-name`)
2020-03-07 11:45:40 +08:00
## Rule details
Enforce `it`, `test` and `describe` to have descriptions that begin with a
lowercase letter. This provides more readable test failures. This rule is not
enabled by default.
The following pattern is considered a warning:
```js
it('Adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
```
The following pattern is not considered a warning:
```js
it('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
```
## Options
```json
{
"jest/lowercase-name": [
"error",
{
"ignore": ["describe", "test"]
}
]
}
```
### `ignore`
This array option whitelists function names so that this rule does not report
their usage as being incorrect. There are three possible values:
- `"describe"`
- `"test"`
- `"it"`
By default, none of these options are enabled (the equivalent of
`{ "ignore": [] }`).
Example of **correct** code for the `{ "ignore": ["describe"] }` option:
```js
/* eslint jest/lowercase-name: ["error", { "ignore": ["describe"] }] */
describe('Uppercase description');
```
Example of **correct** code for the `{ "ignore": ["test"] }` option:
```js
/* eslint jest/lowercase-name: ["error", { "ignore": ["test"] }] */
test('Uppercase description');
```
Example of **correct** code for the `{ "ignore": ["it"] }` option:
```js
/* eslint jest/lowercase-name: ["error", { "ignore": ["it"] }] */
it('Uppercase description');
```
2020-03-31 20:40:00 +08:00
### `allowedPrefixes`
2020-03-07 11:45:40 +08:00
This array option whitelists prefixes that titles can start with with capitals.
This can be useful when writing tests for api endpoints, where you'd like to
prefix with the HTTP method.
2020-03-31 20:40:00 +08:00
By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
2020-03-07 11:45:40 +08:00
2020-03-31 20:40:00 +08:00
Example of **correct** code for the `{ "allowedPrefixes": ["GET"] }` option:
2020-03-07 11:45:40 +08:00
```js
2020-03-31 20:40:00 +08:00
/* eslint jest/lowercase-name: ["error", { "allowedPrefixes": ["GET"] }] */
2020-03-07 11:45:40 +08:00
describe('GET /live');
```
2020-06-27 02:01:06 +08:00
### `ignoreTopLevelDescribe`
This option can be set to allow only the top-level `describe` blocks to have a
title starting with an upper-case letter.
Example of **correct** code for the `{ "ignoreTopLevelDescribe": true }` option:
```js
/* eslint jest/lowercase-name: ["error", { "ignoreTopLevelDescribe": true }] */
describe('MyClass', () => {
describe('#myMethod', () => {
it('does things', () => {
//
});
});
});
```