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