source: frontend/node_modules/eslint-plugin-jest/docs/rules/prefer-lowercase-title.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.4 KB
Line 
1# Enforce lowercase test names (`prefer-lowercase-title`)
2
3## Rule details
4
5Enforce `it`, `test` and `describe` to have descriptions that begin with a
6lowercase letter. This provides more readable test failures. This rule is not
7enabled by default.
8
9The following pattern is considered a warning:
10
11```js
12it('Adds 1 + 2 to equal 3', () => {
13 expect(sum(1, 2)).toBe(3);
14});
15```
16
17The following pattern is not considered a warning:
18
19```js
20it('adds 1 + 2 to equal 3', () => {
21 expect(sum(1, 2)).toBe(3);
22});
23```
24
25## Options
26
27```json
28{
29 "jest/prefer-lowercase-title": [
30 "error",
31 {
32 "ignore": ["describe", "test"]
33 }
34 ]
35}
36```
37
38### `ignore`
39
40This array option controls which Jest functions are checked by this rule. There
41are three possible values:
42
43- `"describe"`
44- `"test"`
45- `"it"`
46
47By default, none of these options are enabled (the equivalent of
48`{ "ignore": [] }`).
49
50Example of **correct** code for the `{ "ignore": ["describe"] }` option:
51
52```js
53/* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["describe"] }] */
54
55describe('Uppercase description');
56```
57
58Example of **correct** code for the `{ "ignore": ["test"] }` option:
59
60```js
61/* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["test"] }] */
62
63test('Uppercase description');
64```
65
66Example of **correct** code for the `{ "ignore": ["it"] }` option:
67
68```js
69/* eslint jest/prefer-lowercase-title: ["error", { "ignore": ["it"] }] */
70
71it('Uppercase description');
72```
73
74### `allowedPrefixes`
75
76This array option allows specifying prefixes which contain capitals that titles
77can start with. This can be useful when writing tests for api endpoints, where
78you'd like to prefix with the HTTP method.
79
80By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
81
82Example of **correct** code for the `{ "allowedPrefixes": ["GET"] }` option:
83
84```js
85/* eslint jest/prefer-lowercase-title: ["error", { "allowedPrefixes": ["GET"] }] */
86
87describe('GET /live');
88```
89
90### `ignoreTopLevelDescribe`
91
92This option can be set to allow only the top-level `describe` blocks to have a
93title starting with an upper-case letter.
94
95Example of **correct** code for the `{ "ignoreTopLevelDescribe": true }` option:
96
97```js
98/* eslint jest/prefer-lowercase-title: ["error", { "ignoreTopLevelDescribe": true }] */
99describe('MyClass', () => {
100 describe('#myMethod', () => {
101 it('does things', () => {
102 //
103 });
104 });
105});
106```
Note: See TracBrowser for help on using the repository browser.