You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/rules/no-setup-in-describe.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,11 @@ Any setup directly in a `describe` is run before all tests execute. This is unde
21
21
1. When doing TDD in a large codebase, all setup is run for tests that don't have `only` set. This can add a substantial amount of time per iteration.
22
22
2. If global state is altered by the setup of another describe block, your test may be affected.
23
23
24
-
This rule reports all function calls and use of the dot operator (due to getters and setters) directly in describe blocks. An exception is made for Mocha's suite configuration methods, like `this.timeout();`, which do not represent setup logic.
24
+
For this rule, "setup" means code that executes immediately while the suite callback itself is evaluated. That includes work done directly in the suite body before any tests run, even when the code looks harmless.
25
+
26
+
In practice, this rule reports direct function calls and direct property access in suite bodies. Property access is included because getters can execute code. Exceptions are made for Mocha's structural calls (`describe`, `it`, hooks, and their supported variants) and Mocha suite configuration calls such as `this.timeout();`, `it(...).timeout();`, or `before(...).timeout();`.
27
+
28
+
This rule does not make special exceptions for JavaScript builtins. For example, `Symbol()` is still a direct function call in the suite body and is reported by default.
25
29
26
30
If you're using [dynamically generated tests](https://mochajs.org/#dynamically-generating-tests), you should disable this rule.
27
31
@@ -75,3 +79,40 @@ describe('something', function () {
75
79
it('should take awhile', function () {});
76
80
});
77
81
```
82
+
83
+
## Options
84
+
85
+
This rule accepts one optional object:
86
+
87
+
-`allow`: an array of call names that should be allowed directly in suite bodies
88
+
89
+
Entries may be written with or without `()`. Dotted names are supported.
90
+
91
+
```json
92
+
{
93
+
"rules": {
94
+
"mocha/no-setup-in-describe": ["error", {
95
+
"allow": ["Symbol", "Object.freeze"]
96
+
}]
97
+
}
98
+
}
99
+
```
100
+
101
+
With this option, the following patterns would not be considered problems:
102
+
103
+
```js
104
+
describe('something', function () {
105
+
consttoken=Symbol('id');
106
+
Object.freeze(sharedFixture);
107
+
it('should work', function () {});
108
+
});
109
+
```
110
+
111
+
The `allow` option only applies to calls. It does not allow bare property access:
0 commit comments