source: frontend/node_modules/eslint-plugin-jest/docs/rules/max-nested-describe.md

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.8 KB
Line 
1# Enforces a maximum depth to nested describe calls (`max-nested-describe`)
2
3While it's useful to be able to group your tests together within the same file
4using `describe()`, having too many levels of nesting throughout your tests make
5them difficult to read.
6
7## Rule Details
8
9This rule enforces a maximum depth to nested `describe()` calls to improve code
10clarity in your tests.
11
12The following patterns are considered warnings (with the default option of
13`{ "max": 5 } `):
14
15```js
16describe('foo', () => {
17 describe('bar', () => {
18 describe('baz', () => {
19 describe('qux', () => {
20 describe('quxx', () => {
21 describe('too many', () => {
22 it('should get something', () => {
23 expect(getSomething()).toBe('Something');
24 });
25 });
26 });
27 });
28 });
29 });
30});
31
32describe('foo', function () {
33 describe('bar', function () {
34 describe('baz', function () {
35 describe('qux', function () {
36 describe('quxx', function () {
37 describe('too many', function () {
38 it('should get something', () => {
39 expect(getSomething()).toBe('Something');
40 });
41 });
42 });
43 });
44 });
45 });
46});
47```
48
49The following patterns are **not** considered warnings (with the default option
50of `{ "max": 5 } `):
51
52```js
53describe('foo', () => {
54 describe('bar', () => {
55 it('should get something', () => {
56 expect(getSomething()).toBe('Something');
57 });
58 });
59
60 describe('qux', () => {
61 it('should get something', () => {
62 expect(getSomething()).toBe('Something');
63 });
64 });
65});
66
67describe('foo2', function () {
68 it('should get something', () => {
69 expect(getSomething()).toBe('Something');
70 });
71});
72
73describe('foo', function () {
74 describe('bar', function () {
75 describe('baz', function () {
76 describe('qux', function () {
77 describe('this is the limit', function () {
78 it('should get something', () => {
79 expect(getSomething()).toBe('Something');
80 });
81 });
82 });
83 });
84 });
85});
86```
87
88## Options
89
90```json
91{
92 "jest/max-nested-describe": [
93 "error",
94 {
95 "max": 5
96 }
97 ]
98}
99```
100
101### `max`
102
103Enforces a maximum depth for nested `describe()`.
104
105This has a default value of `5`.
106
107Examples of patterns **not** considered warnings with options set to
108`{ "max": 2 }`:
109
110```js
111describe('foo', () => {
112 describe('bar', () => {
113 it('should get something', () => {
114 expect(getSomething()).toBe('Something');
115 });
116 });
117});
118
119describe('foo2', function () {
120 describe('bar2', function () {
121 it('should get something', function () {
122 expect(getSomething()).toBe('Something');
123 });
124
125 it('should get else', function () {
126 expect(getSomething()).toBe('Something');
127 });
128 });
129});
130```
Note: See TracBrowser for help on using the repository browser.