File tree Expand file tree Collapse file tree 8 files changed +492
-38
lines changed Expand file tree Collapse file tree 8 files changed +492
-38
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ installations requiring long-term consistency.
112112| [ no-alias-methods] [ ] | Disallow alias methods | ![ recommended] [ ] | ![ fixable-green] [ ] |
113113| [ no-disabled-tests] [ ] | Disallow disabled tests | ![ recommended] [ ] | |
114114| [ no-commented-out-tests] [ ] | Disallow commented out tests | | |
115+ | [ no-duplicate-hooks] [ ] | Disallow duplicate hooks withing a ` describe ` block | | |
115116| [ no-empty-title] [ ] | Disallow empty titles | | |
116117| [ no-focused-tests] [ ] | Disallow focused tests | ![ recommended] [ ] | |
117118| [ no-hooks] [ ] | Disallow setup and teardown hooks | | |
@@ -158,6 +159,7 @@ https://github.com/dangreenisrael/eslint-plugin-jest-formatting
158159[ lowercase-name ] : docs/rules/lowercase-name.md
159160[ no-alias-methods ] : docs/rules/no-alias-methods.md
160161[ no-disabled-tests ] : docs/rules/no-disabled-tests.md
162+ [ no-duplicate-hooks ] : docs/rules/no-duplicate-hooks.md
161163[ no-commented-out-tests ] : docs/rules/no-commented-out-tests.md
162164[ no-empty-title ] : docs/rules/no-empty-title.md
163165[ no-focused-tests ] : docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change 1+ # Disallow duplicate setup and teardown hooks (no-duplicate-hooks)
2+
3+ A describe block should not contain duplicate hooks.
4+
5+ ## Rule Details
6+
7+ Examples of ** incorrect** code for this rule
8+
9+ ``` js
10+ /* eslint jest/no-duplicate-hooks: "error" */
11+
12+ describe (' foo' , () => {
13+ beforeEach (() => {
14+ // some setup
15+ });
16+ beforeEach (() => {
17+ // some setup
18+ });
19+ test (' foo_test' , () => {
20+ // some test
21+ });
22+ });
23+
24+ // Nested describe scenario
25+ describe (' foo' , () => {
26+ beforeEach (() => {
27+ // some setup
28+ });
29+ test (' foo_test' , () => {
30+ // some test
31+ });
32+ describe (' bar' , () => {
33+ test (' bar_test' , () => {
34+ afterAll (() => {
35+ // some teardown
36+ });
37+ afterAll (() => {
38+ // some teardown
39+ });
40+ });
41+ });
42+ });
43+ ```
44+
45+ Examples of ** correct** code for this rule
46+
47+ ``` js
48+ /* eslint jest/no-duplicate-hooks: "error" */
49+
50+ describe (' foo' , () => {
51+ beforeEach (() => {
52+ // some setup
53+ });
54+ test (' foo_test' , () => {
55+ // some test
56+ });
57+ });
58+
59+ // Nested describe scenario
60+ describe (' foo' , () => {
61+ beforeEach (() => {
62+ // some setup
63+ });
64+ test (' foo_test' , () => {
65+ // some test
66+ });
67+ describe (' bar' , () => {
68+ test (' bar_test' , () => {
69+ beforeEach (() => {
70+ // some setup
71+ });
72+ });
73+ });
74+ });
75+ ```
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const path = require('path');
55const { rules } = require ( '../' ) ;
66
77const ruleNames = Object . keys ( rules ) ;
8- const numberOfRules = 32 ;
8+ const numberOfRules = 33 ;
99
1010describe ( 'rules' , ( ) => {
1111 it ( 'should have a corresponding doc for each rule' , ( ) => {
You can’t perform that action at this time.
0 commit comments