eslint-plugin-jest-dom 4.0.2 → 4.0.3

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.
@@ -4,17 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.meta = exports.create = void 0;
7
-
8
7
  var _queries = require("../queries");
9
-
10
8
  var _assignmentAst = require("../assignment-ast");
11
-
12
9
  /**
13
10
  * @fileoverview prefer toBeInTheDocument over checking getAttribute/hasAttribute
14
11
  * @author Anton Niklasson
15
12
  */
16
13
 
17
14
  /*eslint complexity: ["error", {"max": 20}]*/
15
+
18
16
  const meta = {
19
17
  type: "suggestion",
20
18
  docs: {
@@ -29,40 +27,32 @@ const meta = {
29
27
  }
30
28
  };
31
29
  exports.meta = meta;
32
-
33
30
  function isAntonymMatcher(matcherNode, matcherArguments) {
34
31
  return matcherNode.name === "toBeNull" || matcherNode.name === "toBeFalsy" || usesToBeOrToEqualWithNull(matcherNode, matcherArguments) || usesToHaveLengthZero(matcherNode, matcherArguments);
35
32
  }
36
-
37
33
  function usesToBeOrToEqualWithNull(matcherNode, matcherArguments) {
38
34
  return (matcherNode.name === "toBe" || matcherNode.name === "toEqual") && matcherArguments[0].value === null;
39
35
  }
40
-
41
36
  function usesToHaveLengthZero(matcherNode, matcherArguments) {
42
- return matcherNode.name === "toHaveLength" && matcherArguments[0].value === 0;
37
+ // matcherArguments.length === 0: toHaveLength() will cause jest matcher error
38
+ // matcherArguments[0].value: toHaveLength(0, ...) means zero length
39
+ return matcherNode.name === "toHaveLength" && (matcherArguments.length === 0 || matcherArguments[0].value === 0);
43
40
  }
44
-
45
41
  const create = context => {
46
42
  const alternativeMatchers = /^(toHaveLength|toBeDefined|toBeNull|toBe|toEqual|toBeTruthy|toBeFalsy)$/;
47
-
48
43
  function getLengthValue(matcherArguments) {
49
44
  let lengthValue;
50
-
51
45
  if (matcherArguments[0].type === "Identifier") {
52
46
  const assignment = (0, _assignmentAst.getAssignmentForIdentifier)(context, matcherArguments[0].name);
53
-
54
47
  if (!assignment) {
55
48
  return;
56
49
  }
57
-
58
50
  lengthValue = assignment.value;
59
51
  } else if (matcherArguments[0].type === "Literal") {
60
52
  lengthValue = matcherArguments[0].value;
61
53
  }
62
-
63
54
  return lengthValue;
64
55
  }
65
-
66
56
  function check({
67
57
  queryNode,
68
58
  matcherNode,
@@ -72,47 +62,51 @@ const create = context => {
72
62
  }) {
73
63
  if (matcherNode.parent.parent.type !== "CallExpression") {
74
64
  return;
75
- } // only report on dom nodes which we can resolve to RTL queries.
76
-
65
+ }
77
66
 
78
- if (!queryNode || !queryNode.name && !queryNode.property) return; // toHaveLength() is only invalid with 0 or 1
67
+ // only report on dom nodes which we can resolve to RTL queries.
68
+ if (!queryNode || !queryNode.name && !queryNode.property) return;
79
69
 
70
+ // toHaveLength() is only invalid with 0 or 1
80
71
  if (matcherNode.name === "toHaveLength" && matcherArguments.length) {
81
- const lengthValue = getLengthValue(matcherArguments); // isNotToHaveLengthZero represents .not.toHaveLength(0) which is a valid use of toHaveLength
82
-
72
+ const lengthValue = getLengthValue(matcherArguments);
73
+ // isNotToHaveLengthZero represents .not.toHaveLength(0) which is a valid use of toHaveLength
83
74
  const isNotToHaveLengthZero = usesToHaveLengthZero(matcherNode, matcherArguments) && negatedMatcher;
84
75
  const isValidUseOfToHaveLength = isNotToHaveLengthZero || !["Literal", "Identifier"].includes(matcherArguments[0].type) || lengthValue === undefined || lengthValue > 1;
85
-
86
76
  if (isValidUseOfToHaveLength) {
87
77
  return;
88
78
  }
89
- } // toBe() or toEqual() are only invalid with null
90
-
79
+ }
91
80
 
81
+ // toBe() or toEqual() are only invalid with null
92
82
  if (matcherNode.name === "toBe" || matcherNode.name === "toEqual") {
93
83
  if (!matcherArguments.length || !usesToBeOrToEqualWithNull(matcherNode, matcherArguments)) {
94
84
  return;
95
85
  }
96
86
  }
97
-
98
87
  const query = queryNode.name || queryNode.property.name;
99
-
100
88
  if (_queries.queries.includes(query)) {
101
89
  context.report({
102
90
  node: matcherNode,
103
91
  messageId: "use-document",
104
92
  loc: matcherNode.loc,
105
-
106
93
  fix(fixer) {
107
- const operations = []; // Remove any arguments in the matcher
94
+ const operations = [];
108
95
 
96
+ // Remove any arguments in the matcher
109
97
  for (const argument of Array.from(matcherArguments)) {
98
+ const sourceCode = context.getSourceCode();
99
+ const token = sourceCode.getTokenAfter(argument);
100
+ if (token.value === "," && token.type === "Punctuator") {
101
+ // Remove commas if toHaveLength had more than one argument or a trailing comma
102
+ operations.push(fixer.replaceText(token, ""));
103
+ }
110
104
  operations.push(fixer.remove(argument));
111
- } // AllBy should not be used with toBeInTheDocument
112
-
113
-
114
- operations.push(fixer.replaceText(queryNode.property || queryNode, query.replace("All", ""))); // Flip the .not if necessary
105
+ }
115
106
 
107
+ // AllBy should not be used with toBeInTheDocument
108
+ operations.push(fixer.replaceText(queryNode.property || queryNode, query.replace("All", "")));
109
+ // Flip the .not if necessary
116
110
  if (isAntonymMatcher(matcherNode, matcherArguments)) {
117
111
  if (negatedMatcher) {
118
112
  operations.push(fixer.replaceTextRange([expect.range[1], matcherNode.range[1]], ".toBeInTheDocument"));
@@ -120,24 +114,21 @@ const create = context => {
120
114
  } else {
121
115
  operations.push(fixer.insertTextBefore(matcherNode, "not."));
122
116
  }
123
- } // Replace the actual matcher
124
-
117
+ }
125
118
 
119
+ // Replace the actual matcher
126
120
  operations.push(fixer.replaceText(matcherNode, "toBeInTheDocument"));
127
121
  return operations;
128
122
  }
129
-
130
123
  });
131
124
  }
132
125
  }
133
-
134
126
  return {
135
127
  // expect(<query>).not.<matcher>
136
128
  [`CallExpression[callee.object.object.callee.name='expect'][callee.object.property.name='not'][callee.property.name=${alternativeMatchers}], CallExpression[callee.object.callee.name='expect'][callee.object.property.name='not'][callee.object.arguments.0.argument.callee.name=${alternativeMatchers}]`](node) {
137
129
  if (!node.callee.object.object.arguments.length) {
138
130
  return;
139
131
  }
140
-
141
132
  const arg = node.callee.object.object.arguments[0];
142
133
  const queryNode = arg.type === "AwaitExpression" ? arg.argument.callee : arg.callee;
143
134
  const matcherNode = node.callee.property;
@@ -151,7 +142,6 @@ const create = context => {
151
142
  expect
152
143
  });
153
144
  },
154
-
155
145
  // // const foo = <query> expect(foo).not.<matcher>
156
146
  [`MemberExpression[object.object.callee.name=expect][object.property.name=not][property.name=${alternativeMatchers}][object.object.arguments.0.type=Identifier]`](node) {
157
147
  const queryNode = (0, _assignmentAst.getAssignmentForIdentifier)(context, node.object.object.arguments[0].name);
@@ -166,7 +156,6 @@ const create = context => {
166
156
  expect
167
157
  });
168
158
  },
169
-
170
159
  // const foo = <query> expect(foo).<matcher>
171
160
  [`MemberExpression[object.callee.name=expect][property.name=${alternativeMatchers}][object.arguments.0.type=Identifier]`](node) {
172
161
  const queryNode = (0, _assignmentAst.getAssignmentForIdentifier)(context, node.object.arguments[0].name);
@@ -179,16 +168,13 @@ const create = context => {
179
168
  matcherArguments
180
169
  });
181
170
  },
182
-
183
171
  // expect(await <query>).<matcher>
184
172
  // expect(<query>).<matcher>
185
173
  [`CallExpression[callee.object.callee.name='expect'][callee.property.name=${alternativeMatchers}], CallExpression[callee.object.callee.name='expect'][callee.object.arguments.0.argument.callee.name=${alternativeMatchers}]`](node) {
186
174
  const arg = node.callee.object.arguments[0];
187
-
188
175
  if (!arg) {
189
176
  return;
190
177
  }
191
-
192
178
  const queryNode = arg.type === "AwaitExpression" ? arg.argument.callee : arg.callee;
193
179
  const matcherNode = node.callee.property;
194
180
  const matcherArguments = node.arguments;
@@ -199,8 +185,6 @@ const create = context => {
199
185
  matcherArguments
200
186
  });
201
187
  }
202
-
203
188
  };
204
189
  };
205
-
206
190
  exports.create = create;
@@ -1,18 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.meta = exports.create = void 0;
9
-
10
8
  var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
11
-
12
9
  /**
13
10
  * @fileoverview prefer toBeDisabled or toBeEnabled over attribute checks
14
11
  * @author Ben Monro
15
12
  */
13
+
16
14
  const meta = {
17
15
  docs: {
18
16
  description: "prefer toBeRequired over checking properties",
@@ -4,14 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.meta = exports.create = void 0;
7
-
8
7
  /**
9
8
  * @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
10
9
  * @author Ben Monro
11
10
  */
11
+
12
12
  //------------------------------------------------------------------------------
13
13
  // Rule Definition
14
14
  //------------------------------------------------------------------------------
15
+
15
16
  const meta = {
16
17
  docs: {
17
18
  category: "Best Practices",
@@ -22,7 +23,6 @@ const meta = {
22
23
  fixable: "code"
23
24
  };
24
25
  exports.meta = meta;
25
-
26
26
  const create = context => ({
27
27
  [`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBeNull/]`](node) {
28
28
  context.report({
@@ -31,7 +31,6 @@ const create = context => ({
31
31
  fix: fixer => [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceTextRange([node.parent.parent.property.range[0], node.parent.parent.parent.range[1]], `not.toHaveAttribute(${context.getSourceCode().getText(node.arguments[0])})`)]
32
32
  });
33
33
  },
34
-
35
34
  [`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toContain$|toMatch$/]`](node) {
36
35
  const sourceCode = context.getSourceCode();
37
36
  context.report({
@@ -40,7 +39,6 @@ const create = context => ({
40
39
  fix: fixer => [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, "toHaveAttribute"), fixer.replaceText(node.parent.parent.parent.arguments[0], `${sourceCode.getText(node.arguments[0])}, expect.string${node.parent.parent.property.name.slice(2)}ing(${sourceCode.getText(node.parent.parent.parent.arguments[0])})`)]
41
40
  });
42
41
  },
43
-
44
42
  [`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
45
43
  const arg = node.parent.parent.parent.arguments;
46
44
  const isNull = arg.length > 0 && arg[0].value === null;
@@ -54,21 +52,18 @@ const create = context => ({
54
52
  }
55
53
  });
56
54
  },
57
-
58
55
  [`CallExpression[callee.property.name='hasAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBeNull|toBeUndefined|toBeDefined/]`](node) {
59
56
  context.report({
60
57
  node: node.parent.parent.property,
61
58
  message: "Invalid matcher for hasAttribute"
62
59
  });
63
60
  },
64
-
65
61
  [`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBeUndefined|toBeDefined/]`](node) {
66
62
  context.report({
67
63
  node: node.parent.parent.property,
68
64
  message: "Invalid matcher for getAttribute"
69
65
  });
70
66
  },
71
-
72
67
  [`CallExpression[callee.property.name='hasAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
73
68
  if (typeof node.parent.parent.parent.arguments[0].value === "boolean") {
74
69
  context.report({
@@ -83,7 +78,6 @@ const create = context => ({
83
78
  });
84
79
  }
85
80
  },
86
-
87
81
  [`CallExpression[callee.property.name='hasAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBeTruthy|toBeFalsy/]`](node) {
88
82
  context.report({
89
83
  node: node.parent,
@@ -91,7 +85,5 @@ const create = context => ({
91
85
  fix: fixer => [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceTextRange([node.parent.parent.property.range[0], node.parent.parent.parent.range[1]], `${node.parent.parent.property.name === "toBeFalsy" ? "not." : ""}toHaveAttribute(${context.getSourceCode().getText(node.arguments[0])})`)]
92
86
  });
93
87
  }
94
-
95
88
  });
96
-
97
89
  exports.create = create;
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.meta = exports.create = void 0;
7
-
8
7
  var _assignmentAst = require("../assignment-ast");
9
-
10
8
  /**
11
9
  * @fileoverview prefer toHaveClass over checking element className
12
10
  * @author Ben Monro
13
11
  */
12
+
14
13
  //------------------------------------------------------------------------------
15
14
  // Rule Definition
16
15
  //------------------------------------------------------------------------------
16
+
17
17
  const messageId = "use-to-have-class";
18
18
  const meta = {
19
19
  docs: {
@@ -28,7 +28,6 @@ const meta = {
28
28
  fixable: "code"
29
29
  };
30
30
  exports.meta = meta;
31
-
32
31
  const create = context => ({
33
32
  //expect(el.classList.contains("foo")).toBe(true)
34
33
  [`CallExpression[callee.object.callee.name=expect][callee.object.arguments.0.callee.object.property.name=classList][callee.object.arguments.0.callee.property.name=contains][callee.property.name=/toBe(Truthy|Falsy)?|to(Strict)?Equal/]`](node) {
@@ -41,16 +40,13 @@ const create = context => ({
41
40
  context.report({
42
41
  node: matcher,
43
42
  messageId,
44
-
45
43
  fix(fixer) {
46
44
  return [fixer.removeRange([checkedProp.range[1], expectArg.range[1]]), fixer.replaceText(matcher, `${isTruthy ? "" : "not."}toHaveClass`), matcherArg ? fixer.replaceText(matcherArg, context.getSourceCode().getText(classValue)) : fixer.insertTextBefore(context.getSourceCode().getTokenAfter(matcher, {
47
45
  skip: 1
48
46
  }), context.getSourceCode().getText(classValue))];
49
47
  }
50
-
51
48
  });
52
49
  },
53
-
54
50
  //expect(el.classList[0]).toBe("bar")
55
51
  [`CallExpression[callee.object.callee.name=expect][callee.object.arguments.0.object.property.name=classList][callee.property.name=/toBe$|to(Strict)?Equal|toContain/][arguments.0.type=/Literal$/]`](node) {
56
52
  const [classValue] = node.arguments;
@@ -60,16 +56,13 @@ const create = context => ({
60
56
  context.report({
61
57
  node: matcher,
62
58
  messageId,
63
-
64
59
  fix(fixer) {
65
60
  //can't autofix here as it toHaveClass doesn't have a partial matcher / regex for class names.
66
61
  if (matcher.name === "toContain") return;
67
62
  return [fixer.removeRange([classNameProp.object.range[1], expectArg.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, context.getSourceCode().getText(classValue))];
68
63
  }
69
-
70
64
  });
71
65
  },
72
-
73
66
  //expect(el.classList[0]).not.toBe("bar")
74
67
  [`CallExpression[callee.object.object.callee.name=expect][callee.object.object.arguments.0.object.property.name=classList][callee.object.property.name=not][callee.property.name=/toBe$|to(Strict)?Equal|toContain/][arguments.0.type=/Literal$/]`](node) {
75
68
  //can't autofix this case because the class could be in another element of the classList array.
@@ -78,7 +71,6 @@ const create = context => ({
78
71
  messageId
79
72
  });
80
73
  },
81
-
82
74
  //expect(el.className | el.classList).toBe("bar") / toStrict?Equal / toContain
83
75
  [`CallExpression[callee.object.callee.name=expect][callee.object.arguments.0.property.name=/class(Name|List)/][callee.property.name=/toBe$|to(Strict)?Equal|toContain/]`](node) {
84
76
  const checkedProp = node.callee.object.arguments[0].property;
@@ -88,27 +80,23 @@ const create = context => ({
88
80
  const {
89
81
  isDTLQuery
90
82
  } = (0, _assignmentAst.getQueryNodeFrom)(context, classNameProp);
91
- if (!isDTLQuery) return; // don't report here if using `expect.foo()`
83
+ if (!isDTLQuery) return;
84
+ // don't report here if using `expect.foo()`
92
85
 
93
86
  if (classValue.type === "CallExpression" && classValue.callee.type === "MemberExpression" && classValue.callee.object.name === "expect") {
94
87
  return;
95
88
  }
96
-
97
89
  context.report({
98
90
  node: matcher,
99
91
  messageId,
100
-
101
92
  fix(fixer) {
102
93
  if (checkedProp.name === "classList" && matcher.name !== "toContain") {
103
94
  return;
104
95
  }
105
-
106
96
  return [fixer.removeRange([classNameProp.range[1], checkedProp.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, `${context.getSourceCode().getText(classValue)}${matcher.name === "toContain" ? "" : ", { exact: true }"}`)];
107
97
  }
108
-
109
98
  });
110
99
  },
111
-
112
100
  //expect(el.className | el.classList).toEqual(expect.stringContaining("foo") | objectContaining) / toStrictEqual
113
101
  [`CallExpression[callee.object.callee.name=expect][callee.object.arguments.0.property.name=/class(Name|List)/][callee.property.name=/to(Strict)?Equal/][arguments.0.callee.object.name=expect]`](node) {
114
102
  const className = node.callee.object.arguments[0].property;
@@ -123,15 +111,12 @@ const create = context => ({
123
111
  context.report({
124
112
  node: matcher,
125
113
  messageId,
126
-
127
114
  fix(fixer) {
128
115
  if (matcherArg.name !== "stringContaining") return;
129
116
  return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(node.arguments[0], `${context.getSourceCode().getText(classValue)}`)];
130
117
  }
131
-
132
118
  });
133
119
  },
134
-
135
120
  //expect(screen.getByRole("button").className | classList).not.toBe("foo"); / toStrict?Equal / toContain
136
121
  [`CallExpression[callee.object.object.callee.name=expect][callee.object.object.arguments.0.property.name=/class(Name|List)/][callee.object.property.name=not][callee.property.name=/toBe$|to(Strict)?Equal|toContain/]`](node) {
137
122
  const className = node.callee.object.object.arguments[0].property;
@@ -145,29 +130,23 @@ const create = context => ({
145
130
  context.report({
146
131
  node: matcher,
147
132
  messageId,
148
-
149
133
  fix(fixer) {
150
134
  if (className.name === "classList" && matcher.name !== "toContain") {
151
135
  return;
152
136
  }
153
-
154
137
  return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, `${context.getSourceCode().getText(classValue)}${matcher.name === "toContain" ? "" : ", { exact: true }"}`)];
155
138
  }
156
-
157
139
  });
158
140
  },
159
-
160
141
  //expect(el).toHaveProperty("className", "foo: bar");
161
142
  //expect(el).toHaveAttribute("class", "foo: bar");
162
143
  [[`CallExpression[callee.object.callee.name=expect][callee.property.name=toHaveAttribute][arguments.0.type=/Literal/][arguments.1.type=/Literal$/]`, `CallExpression[callee.object.callee.name=expect][callee.property.name=toHaveProperty][arguments.0.type=/Literal/][arguments.1.type=/Literal$/]`].join(",")](node) {
163
144
  const matcher = node.callee.property;
164
145
  const [classArg, classValueArg] = node.arguments;
165
146
  const classNameValue = context.getSourceCode().getText(classArg).slice(1, -1);
166
-
167
147
  if (matcher.name === "toHaveAttribute" && classNameValue !== "class" || matcher.name === "toHaveProperty" && classNameValue !== "className") {
168
148
  return;
169
149
  }
170
-
171
150
  const {
172
151
  isDTLQuery
173
152
  } = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
@@ -175,14 +154,11 @@ const create = context => ({
175
154
  context.report({
176
155
  node: matcher,
177
156
  messageId,
178
-
179
157
  fix(fixer) {
180
158
  return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg, context.getSourceCode().getText(classValueArg)), fixer.replaceText(classValueArg, `{ exact: true }`)];
181
159
  }
182
-
183
160
  });
184
161
  },
185
-
186
162
  //expect(el).not.toHaveAttribute("class", "foo: bar");
187
163
  //expect(el).not.toHaveProperty("className", "foo: bar");
188
164
  [[`CallExpression[callee.object.object.callee.name=expect][callee.object.property.name=not][callee.property.name=toHaveAttribute][arguments.0.type=/Literal/][arguments.1.type=/Literal$/]`, `CallExpression[callee.object.object.callee.name=expect][callee.object.property.name=not][callee.property.name=toHaveProperty][arguments.0.type=/Literal/][arguments.1.type=/Literal$/]`].join(",")](node) {
@@ -190,11 +166,9 @@ const create = context => ({
190
166
  const matcher = node.callee.property;
191
167
  const [classArg, classValueArg] = node.arguments;
192
168
  const classNameValue = context.getSourceCode().getText(classArg).slice(1, -1);
193
-
194
169
  if (matcher.name === "toHaveAttribute" && classNameValue !== "class" || matcher.name === "toHaveProperty" && classNameValue !== "className") {
195
170
  return;
196
171
  }
197
-
198
172
  const {
199
173
  isDTLQuery
200
174
  } = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.object.arguments[0]);
@@ -202,14 +176,11 @@ const create = context => ({
202
176
  context.report({
203
177
  node: matcher,
204
178
  messageId,
205
-
206
179
  fix(fixer) {
207
180
  return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg, context.getSourceCode().getText(classValueArg)), fixer.replaceText(classValueArg, `{ exact: true }`)];
208
181
  }
209
-
210
182
  });
211
183
  },
212
-
213
184
  //expect(el).toHaveProperty(`className`, expect.stringContaining("foo"));
214
185
  //expect(el).toHaveAttribute(`class`, expect.stringContaining("foo"));
215
186
  [[`CallExpression[callee.object.callee.name=expect][callee.property.name=toHaveAttribute][arguments.0.type=/Literal/][arguments.1.callee.object.name=expect][arguments.1.callee.property.name=stringContaining]`, `CallExpression[callee.object.callee.name=expect][callee.property.name=toHaveProperty][arguments.0.type=/Literal/][arguments.1.callee.object.name=expect][arguments.1.callee.property.name=stringContaining]`].join(",")](node) {
@@ -217,11 +188,9 @@ const create = context => ({
217
188
  const [classArg, classValue] = node.arguments;
218
189
  const classValueArg = classValue.arguments[0];
219
190
  const classNameValue = context.getSourceCode().getText(classArg).slice(1, -1);
220
-
221
191
  if (matcher.name === "toHaveAttribute" && classNameValue !== "class" || matcher.name === "toHaveProperty" && classNameValue !== "className") {
222
192
  return;
223
193
  }
224
-
225
194
  const {
226
195
  isDTLQuery
227
196
  } = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
@@ -229,14 +198,10 @@ const create = context => ({
229
198
  context.report({
230
199
  node: matcher,
231
200
  messageId,
232
-
233
201
  fix(fixer) {
234
202
  return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg, context.getSourceCode().getText(classValueArg)), fixer.removeRange([classArg.range[1], classValue.range[1]])];
235
203
  }
236
-
237
204
  });
238
205
  }
239
-
240
206
  });
241
-
242
207
  exports.create = create;