source: frontend/node_modules/eslint-plugin-jest/docs/rules/consistent-test-it.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: 1.7 KB
Line 
1# Have control over `test` and `it` usages (`consistent-test-it`)
2
3Jest allows you to choose how you want to define your tests, using the `it` or
4the `test` keywords, with multiple permutations for each:
5
6- **it:** `it`, `xit`, `fit`, `it.only`, `it.skip`.
7- **test:** `test`, `xtest`, `test.only`, `test.skip`.
8
9This rule gives you control over the usage of these keywords in your codebase.
10
11## Rule Details
12
13This rule can be configured as follows
14
15```json5
16{
17 type: 'object',
18 properties: {
19 fn: {
20 enum: ['it', 'test'],
21 },
22 withinDescribe: {
23 enum: ['it', 'test'],
24 },
25 },
26 additionalProperties: false,
27}
28```
29
30#### fn
31
32Decides whether to use `test` or `it`.
33
34#### withinDescribe
35
36Decides whether to use `test` or `it` within a `describe` scope.
37
38```js
39/*eslint jest/consistent-test-it: ["error", {"fn": "test"}]*/
40
41test('foo'); // valid
42test.only('foo'); // valid
43
44it('foo'); // invalid
45it.only('foo'); // invalid
46```
47
48```js
49/*eslint jest/consistent-test-it: ["error", {"fn": "it"}]*/
50
51it('foo'); // valid
52it.only('foo'); // valid
53
54test('foo'); // invalid
55test.only('foo'); // invalid
56```
57
58```js
59/*eslint jest/consistent-test-it: ["error", {"fn": "it", "withinDescribe": "test"}]*/
60
61it('foo'); // valid
62describe('foo', function () {
63 test('bar'); // valid
64});
65
66test('foo'); // invalid
67describe('foo', function () {
68 it('bar'); // invalid
69});
70```
71
72### Default configuration
73
74The default configuration forces all top-level tests to use `test` and all tests
75nested within `describe` to use `it`.
76
77```js
78/*eslint jest/consistent-test-it: ["error"]*/
79
80test('foo'); // valid
81describe('foo', function () {
82 it('bar'); // valid
83});
84
85it('foo'); // invalid
86describe('foo', function () {
87 test('bar'); // invalid
88});
89```
Note: See TracBrowser for help on using the repository browser.