eslint-plugin-jest 26.0.0 → 26.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,6 +158,7 @@ installations requiring long-term consistency.
158
158
  | [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![style][] | ![fixable][] |
159
159
  | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
160
160
  | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | |
161
+ | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | |
161
162
  | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | ![recommended][] | ![fixable][] |
162
163
  | [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended][] | |
163
164
  | [no-done-callback](docs/rules/no-done-callback.md) | Avoid using a callback in asynchronous tests and hooks | ![recommended][] | ![suggest][] |
@@ -0,0 +1,79 @@
1
+ # Disallow conditional logic in tests (`no-conditional-in-test`)
2
+
3
+ Conditional logic in tests is usually an indication that a test is attempting to
4
+ cover too much, and not testing the logic it intends to. Each branch of code
5
+ executing within a conditional statement will usually be better served by a test
6
+ devoted to it.
7
+
8
+ ## Rule Details
9
+
10
+ This rule reports on any use of a conditional statement such as `if`, `switch`,
11
+ and ternary expressions.
12
+
13
+ Examples of **incorrect** code for this rule:
14
+
15
+ ```js
16
+ it('foo', () => {
17
+ if (true) {
18
+ doTheThing();
19
+ }
20
+ });
21
+
22
+ it('bar', () => {
23
+ switch (mode) {
24
+ case 'none':
25
+ generateNone();
26
+ case 'single':
27
+ generateOne();
28
+ case 'multiple':
29
+ generateMany();
30
+ }
31
+
32
+ expect(fixtures.length).toBeGreaterThan(-1);
33
+ });
34
+
35
+ it('baz', async () => {
36
+ const promiseValue = () => {
37
+ return something instanceof Promise
38
+ ? something
39
+ : Promise.resolve(something);
40
+ };
41
+
42
+ await expect(promiseValue()).resolves.toBe(1);
43
+ });
44
+ ```
45
+
46
+ Examples of **correct** code for this rule:
47
+
48
+ ```js
49
+ describe('my tests', () => {
50
+ if (true) {
51
+ it('foo', () => {
52
+ doTheThing();
53
+ });
54
+ }
55
+ });
56
+
57
+ beforeEach(() => {
58
+ switch (mode) {
59
+ case 'none':
60
+ generateNone();
61
+ case 'single':
62
+ generateOne();
63
+ case 'multiple':
64
+ generateMany();
65
+ }
66
+ });
67
+
68
+ it('bar', () => {
69
+ expect(fixtures.length).toBeGreaterThan(-1);
70
+ });
71
+
72
+ const promiseValue = something => {
73
+ return something instanceof Promise ? something : Promise.resolve(something);
74
+ };
75
+
76
+ it('baz', async () => {
77
+ await expect(promiseValue()).resolves.toBe(1);
78
+ });
79
+ ```
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("./utils");
9
+
10
+ var _default = (0, _utils.createRule)({
11
+ name: __filename,
12
+ meta: {
13
+ docs: {
14
+ description: 'Disallow conditional logic in tests',
15
+ category: 'Best Practices',
16
+ recommended: false
17
+ },
18
+ messages: {
19
+ conditionalInTest: 'Avoid having conditionals in tests'
20
+ },
21
+ type: 'problem',
22
+ schema: []
23
+ },
24
+ defaultOptions: [],
25
+
26
+ create(context) {
27
+ let inTestCase = false;
28
+
29
+ const maybeReportConditional = node => {
30
+ if (inTestCase) {
31
+ context.report({
32
+ messageId: 'conditionalInTest',
33
+ node
34
+ });
35
+ }
36
+ };
37
+
38
+ return {
39
+ CallExpression(node) {
40
+ if ((0, _utils.isTestCaseCall)(node)) {
41
+ inTestCase = true;
42
+ }
43
+ },
44
+
45
+ 'CallExpression:exit'(node) {
46
+ if ((0, _utils.isTestCaseCall)(node)) {
47
+ inTestCase = false;
48
+ }
49
+ },
50
+
51
+ IfStatement: maybeReportConditional,
52
+ SwitchStatement: maybeReportConditional,
53
+ ConditionalExpression: maybeReportConditional,
54
+ LogicalExpression: maybeReportConditional
55
+ };
56
+ }
57
+
58
+ });
59
+
60
+ exports.default = _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "26.0.0",
4
- "description": "Eslint rules for Jest",
3
+ "version": "26.1.0-next.1",
4
+ "description": "ESLint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
7
7
  "eslintplugin",
@@ -112,7 +112,7 @@
112
112
  "eslint-plugin-node": "^11.0.0",
113
113
  "eslint-plugin-prettier": "^3.4.1",
114
114
  "eslint-remote-tester": "^2.1.0",
115
- "eslint-remote-tester-repositories": "^0.0.3",
115
+ "eslint-remote-tester-repositories": "^0.0.4",
116
116
  "husky": "^7.0.2",
117
117
  "is-ci": "^3.0.0",
118
118
  "jest": "^27.0.0",
@@ -121,7 +121,7 @@
121
121
  "pinst": "^2.0.0",
122
122
  "prettier": "^2.0.5",
123
123
  "rimraf": "^3.0.0",
124
- "semantic-release": "^18.0.0",
124
+ "semantic-release": "^19.0.0",
125
125
  "semver": "^7.3.5",
126
126
  "ts-node": "^10.2.1",
127
127
  "typescript": "^4.4.0"
@@ -159,7 +159,9 @@
159
159
  ]
160
160
  },
161
161
  "resolutions": {
162
- "@typescript-eslint/experimental-utils": "^5.0.0"
162
+ "@semantic-release/npm/npm": "7.20.6",
163
+ "@typescript-eslint/experimental-utils": "^5.0.0",
164
+ "fsevents/node-gyp": "^7.0.0"
163
165
  },
164
166
  "packageManager": "yarn@3.1.1"
165
167
  }