eslint-plugin-jest 25.3.1 → 25.3.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [25.3.2](https://github.com/jest-community/eslint-plugin-jest/compare/v25.3.1...v25.3.2) (2021-12-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **no-large-snapshots:** only count size of template string for inline snapshots ([#1005](https://github.com/jest-community/eslint-plugin-jest/issues/1005)) ([5bea38f](https://github.com/jest-community/eslint-plugin-jest/commit/5bea38f9773ab686f08a7cc25247a782d50aa5ed))
7
+ * **prefer-hooks-on-top:** improve message & docs ([#999](https://github.com/jest-community/eslint-plugin-jest/issues/999)) ([f9e7ae2](https://github.com/jest-community/eslint-plugin-jest/commit/f9e7ae29233daad7bfea2230bea7266659299328))
8
+
1
9
  ## [25.3.1](https://github.com/jest-community/eslint-plugin-jest/compare/v25.3.0...v25.3.1) (2021-12-27)
2
10
 
3
11
 
@@ -1,6 +1,10 @@
1
1
  # Suggest having hooks before any test cases (`prefer-hooks-on-top`)
2
2
 
3
- All hooks should be defined before the start of the tests
3
+ While hooks can be setup anywhere in a test file, they are always called in a
4
+ specific order which means it can be confusing if they're intermixed with test
5
+ cases.
6
+
7
+ This rule helps to ensure that hooks are always defined before test cases.
4
8
 
5
9
  ## Rule Details
6
10
 
@@ -11,47 +15,51 @@ Examples of **incorrect** code for this rule
11
15
 
12
16
  describe('foo', () => {
13
17
  beforeEach(() => {
14
- //some hook code
15
- });
16
- test('bar', () => {
17
- some_fn();
18
+ seedMyDatabase();
18
19
  });
19
- beforeAll(() => {
20
- //some hook code
21
- });
22
- test('bar', () => {
23
- some_fn();
20
+
21
+ it('accepts this input', () => {
22
+ // ...
24
23
  });
25
- });
26
24
 
27
- // Nested describe scenario
28
- describe('foo', () => {
29
25
  beforeAll(() => {
30
- //some hook code
26
+ createMyDatabase();
31
27
  });
32
- test('bar', () => {
33
- some_fn();
28
+
29
+ it('returns that value', () => {
30
+ // ...
34
31
  });
35
- describe('inner_foo', () => {
32
+
33
+ describe('when the database has specific values', () => {
34
+ const specificValue = '...';
35
+
36
36
  beforeEach(() => {
37
- //some hook code
37
+ seedMyDatabase(specificValue);
38
38
  });
39
- test('inner bar', () => {
40
- some_fn();
39
+
40
+ it('accepts that input', () => {
41
+ // ...
41
42
  });
42
- test('inner bar', () => {
43
- some_fn();
43
+
44
+ it('throws an error', () => {
45
+ // ...
44
46
  });
45
- beforeAll(() => {
46
- //some hook code
47
+
48
+ afterEach(() => {
49
+ clearLogger();
47
50
  });
48
- afterAll(() => {
49
- //some hook code
51
+ beforeEach(() => {
52
+ mockLogger();
50
53
  });
51
- test('inner bar', () => {
52
- some_fn();
54
+
55
+ it('logs a message', () => {
56
+ // ...
53
57
  });
54
58
  });
59
+
60
+ afterAll(() => {
61
+ removeMyDatabase();
62
+ });
55
63
  });
56
64
  ```
57
65
 
@@ -61,35 +69,51 @@ Examples of **correct** code for this rule
61
69
  /* eslint jest/prefer-hooks-on-top: "error" */
62
70
 
63
71
  describe('foo', () => {
64
- beforeEach(() => {
65
- //some hook code
72
+ beforeAll(() => {
73
+ createMyDatabase();
66
74
  });
67
75
 
68
- // Not affected by rule
69
- someSetup();
70
-
71
- afterEach(() => {
72
- //some hook code
76
+ beforeEach(() => {
77
+ seedMyDatabase();
73
78
  });
74
- test('bar', () => {
75
- some_fn();
79
+
80
+ afterAll(() => {
81
+ clearMyDatabase();
76
82
  });
77
- });
78
83
 
79
- // Nested describe scenario
80
- describe('foo', () => {
81
- beforeEach(() => {
82
- //some hook code
84
+ it('accepts this input', () => {
85
+ // ...
83
86
  });
84
- test('bar', () => {
85
- some_fn();
87
+
88
+ it('returns that value', () => {
89
+ // ...
86
90
  });
87
- describe('inner_foo', () => {
91
+
92
+ describe('when the database has specific values', () => {
93
+ const specificValue = '...';
94
+
88
95
  beforeEach(() => {
89
- //some hook code
96
+ seedMyDatabase(specificValue);
90
97
  });
91
- test('inner bar', () => {
92
- some_fn();
98
+
99
+ beforeEach(() => {
100
+ mockLogger();
101
+ });
102
+
103
+ afterEach(() => {
104
+ clearLogger();
105
+ });
106
+
107
+ it('accepts that input', () => {
108
+ // ...
109
+ });
110
+
111
+ it('throws an error', () => {
112
+ // ...
113
+ });
114
+
115
+ it('logs a message', () => {
116
+ // ...
93
117
  });
94
118
  });
95
119
  });
@@ -100,6 +100,8 @@ var _default = (0, _utils.createRule)({
100
100
 
101
101
  return {
102
102
  CallExpression(node) {
103
+ var _matcher$arguments;
104
+
103
105
  if (!(0, _utils.isExpectCall)(node)) {
104
106
  return;
105
107
  }
@@ -112,10 +114,10 @@ var _default = (0, _utils.createRule)({
112
114
  return;
113
115
  }
114
116
 
115
- if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name)) {
117
+ if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name) && (_matcher$arguments = matcher.arguments) !== null && _matcher$arguments !== void 0 && _matcher$arguments.length) {
116
118
  var _options$inlineMaxSiz;
117
119
 
118
- reportOnViolation(context, matcher.node.parent, { ...options,
120
+ reportOnViolation(context, matcher.arguments[0], { ...options,
119
121
  maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
120
122
  });
121
123
  }
@@ -16,7 +16,7 @@ var _default = (0, _utils.createRule)({
16
16
  recommended: false
17
17
  },
18
18
  messages: {
19
- noHookOnTop: 'Move all hooks before test cases'
19
+ noHookOnTop: 'Hooks should come before test cases'
20
20
  },
21
21
  schema: [],
22
22
  type: 'suggestion'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "25.3.1",
3
+ "version": "25.3.2",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
@@ -89,8 +89,8 @@
89
89
  "@babel/core": "^7.4.4",
90
90
  "@babel/preset-env": "^7.4.4",
91
91
  "@babel/preset-typescript": "^7.3.3",
92
- "@commitlint/cli": "^15.0.0",
93
- "@commitlint/config-conventional": "^15.0.0",
92
+ "@commitlint/cli": "^16.0.0",
93
+ "@commitlint/config-conventional": "^16.0.0",
94
94
  "@schemastore/package": "^0.0.6",
95
95
  "@semantic-release/changelog": "^6.0.0",
96
96
  "@semantic-release/git": "^10.0.0",