eslint-plugin-jest-dom 5.2.0 → 5.4.0
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/dist/assignment-ast.js +13 -10
- package/dist/context.js +23 -0
- package/dist/rules/prefer-empty.js +2 -1
- package/dist/rules/prefer-in-document.js +5 -4
- package/dist/rules/prefer-to-have-attribute.js +4 -3
- package/dist/rules/prefer-to-have-class.js +10 -9
- package/dist/rules/prefer-to-have-style.js +5 -4
- package/dist/rules/prefer-to-have-text-content.js +3 -2
- package/dist/rules/prefer-to-have-value.js +3 -2
- package/package.json +4 -3
package/dist/assignment-ast.js
CHANGED
|
@@ -7,25 +7,27 @@ exports.getAssignmentForIdentifier = getAssignmentForIdentifier;
|
|
|
7
7
|
exports.getInnerNodeFrom = getInnerNodeFrom;
|
|
8
8
|
exports.getQueryNodeFrom = getQueryNodeFrom;
|
|
9
9
|
var _queries = require("./queries");
|
|
10
|
+
var _context = require("./context");
|
|
10
11
|
/**
|
|
11
12
|
* Gets the inner relevant node (CallExpression, Identity, et al.) given a generic expression node
|
|
12
13
|
* await someAsyncFunc() => someAsyncFunc()
|
|
13
14
|
* someElement as HTMLDivElement => someElement
|
|
14
15
|
*
|
|
15
16
|
* @param {Object} context - Context for a rule
|
|
17
|
+
* @param {Object} node - Node for a rule
|
|
16
18
|
* @param {Object} expression - An expression node
|
|
17
19
|
* @returns {Object} - A node
|
|
18
20
|
*/
|
|
19
|
-
function getInnerNodeFrom(context, expression) {
|
|
21
|
+
function getInnerNodeFrom(context, node, expression) {
|
|
20
22
|
switch (expression.type) {
|
|
21
23
|
case "Identifier":
|
|
22
|
-
return getAssignmentForIdentifier(context, expression.name);
|
|
24
|
+
return getAssignmentForIdentifier(context, node, expression.name);
|
|
23
25
|
case "TSAsExpression":
|
|
24
|
-
return getInnerNodeFrom(context, expression.expression);
|
|
26
|
+
return getInnerNodeFrom(context, node, expression.expression);
|
|
25
27
|
case "AwaitExpression":
|
|
26
|
-
return getInnerNodeFrom(context, expression.argument);
|
|
28
|
+
return getInnerNodeFrom(context, node, expression.argument);
|
|
27
29
|
case "MemberExpression":
|
|
28
|
-
return getInnerNodeFrom(context, expression.object);
|
|
30
|
+
return getInnerNodeFrom(context, node, expression.object);
|
|
29
31
|
default:
|
|
30
32
|
return expression;
|
|
31
33
|
}
|
|
@@ -35,17 +37,18 @@ function getInnerNodeFrom(context, expression) {
|
|
|
35
37
|
* Get the node corresponding to the latest assignment to a variable named `identifierName`
|
|
36
38
|
*
|
|
37
39
|
* @param {Object} context - Context for a rule
|
|
40
|
+
* @param {Object} node - Node for a rule
|
|
38
41
|
* @param {String} identifierName - Name of an identifier
|
|
39
42
|
* @returns {Object} - A node, possibly undefined
|
|
40
43
|
*/
|
|
41
|
-
function getAssignmentForIdentifier(context, identifierName) {
|
|
42
|
-
const variable =
|
|
44
|
+
function getAssignmentForIdentifier(context, node, identifierName) {
|
|
45
|
+
const variable = (0, _context.getScope)(context, node).set.get(identifierName);
|
|
43
46
|
if (!variable) return;
|
|
44
47
|
const init = variable.defs[0].node.init;
|
|
45
48
|
let assignmentNode;
|
|
46
49
|
if (init) {
|
|
47
50
|
// let foo = bar;
|
|
48
|
-
assignmentNode = getInnerNodeFrom(context, init);
|
|
51
|
+
assignmentNode = getInnerNodeFrom(context, node, init);
|
|
49
52
|
} else {
|
|
50
53
|
// let foo;
|
|
51
54
|
// foo = bar;
|
|
@@ -53,7 +56,7 @@ function getAssignmentForIdentifier(context, identifierName) {
|
|
|
53
56
|
if (!assignmentRef) {
|
|
54
57
|
return;
|
|
55
58
|
}
|
|
56
|
-
assignmentNode = getInnerNodeFrom(context, assignmentRef.writeExpr);
|
|
59
|
+
assignmentNode = getInnerNodeFrom(context, node, assignmentRef.writeExpr);
|
|
57
60
|
}
|
|
58
61
|
return assignmentNode;
|
|
59
62
|
}
|
|
@@ -67,7 +70,7 @@ function getAssignmentForIdentifier(context, identifierName) {
|
|
|
67
70
|
* @returns {Object} - Object with query, queryArg & isDTLQuery
|
|
68
71
|
*/
|
|
69
72
|
function getQueryNodeFrom(context, nodeWithValueProp) {
|
|
70
|
-
const queryNode = getInnerNodeFrom(context, nodeWithValueProp);
|
|
73
|
+
const queryNode = getInnerNodeFrom(context, nodeWithValueProp, nodeWithValueProp);
|
|
71
74
|
if (!queryNode || !queryNode.callee) {
|
|
72
75
|
return {
|
|
73
76
|
isDTLQuery: false,
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getScope = getScope;
|
|
7
|
+
exports.getSourceCode = getSourceCode;
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
function getSourceCode(context) {
|
|
10
|
+
if ('sourceCode' in context) {
|
|
11
|
+
return context.sourceCode;
|
|
12
|
+
}
|
|
13
|
+
return context.getSourceCode();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* istanbul ignore next */
|
|
17
|
+
function getScope(context, node) {
|
|
18
|
+
const sourceCode = getSourceCode(context);
|
|
19
|
+
if (sourceCode && sourceCode.getScope) {
|
|
20
|
+
return sourceCode.getScope(node);
|
|
21
|
+
}
|
|
22
|
+
return context.getScope();
|
|
23
|
+
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
|
+
var _context = require("../context");
|
|
7
8
|
/**
|
|
8
9
|
* @fileoverview Prefer toBeEmpty over checking innerHTML
|
|
9
10
|
* @author Ben Monro
|
|
@@ -20,7 +21,7 @@ const meta = exports.meta = {
|
|
|
20
21
|
};
|
|
21
22
|
const create = context => {
|
|
22
23
|
function isNonEmptyStringOrTemplateLiteral(node) {
|
|
23
|
-
return !['""', "''", "``", "null"].includes(
|
|
24
|
+
return !['""', "''", "``", "null"].includes((0, _context.getSourceCode)(context).getText(node));
|
|
24
25
|
}
|
|
25
26
|
return {
|
|
26
27
|
[`BinaryExpression[left.property.name='innerHTML'][right.value=''][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
7
|
var _queries = require("../queries");
|
|
8
8
|
var _assignmentAst = require("../assignment-ast");
|
|
9
|
+
var _context = require("../context");
|
|
9
10
|
/**
|
|
10
11
|
* @fileoverview prefer toBeInTheDocument over checking getAttribute/hasAttribute
|
|
11
12
|
* @author Anton Niklasson
|
|
@@ -61,7 +62,7 @@ const create = context => {
|
|
|
61
62
|
function getLengthValue(matcherArguments) {
|
|
62
63
|
let lengthValue;
|
|
63
64
|
if (matcherArguments[0].type === "Identifier") {
|
|
64
|
-
const assignment = (0, _assignmentAst.getAssignmentForIdentifier)(context, matcherArguments[0].name);
|
|
65
|
+
const assignment = (0, _assignmentAst.getAssignmentForIdentifier)(context, matcherArguments[0], matcherArguments[0].name);
|
|
65
66
|
if (!assignment) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
@@ -151,7 +152,7 @@ const create = context => {
|
|
|
151
152
|
|
|
152
153
|
// Remove any arguments in the matcher
|
|
153
154
|
for (const argument of Array.from(matcherArguments)) {
|
|
154
|
-
const sourceCode =
|
|
155
|
+
const sourceCode = (0, _context.getSourceCode)(context);
|
|
155
156
|
const token = sourceCode.getTokenAfter(argument);
|
|
156
157
|
if (token.value === "," && token.type === "Punctuator") {
|
|
157
158
|
// Remove commas if toHaveLength had more than one argument or a trailing comma
|
|
@@ -200,7 +201,7 @@ const create = context => {
|
|
|
200
201
|
},
|
|
201
202
|
// // const foo = <query> expect(foo).not.<matcher>
|
|
202
203
|
[`MemberExpression[object.object.callee.name=expect][object.property.name=not][property.name=${alternativeMatchers}][object.object.arguments.0.type=Identifier]`](node) {
|
|
203
|
-
const queryNode = (0, _assignmentAst.getAssignmentForIdentifier)(context, node.object.object.arguments[0].name);
|
|
204
|
+
const queryNode = (0, _assignmentAst.getAssignmentForIdentifier)(context, node, node.object.object.arguments[0].name);
|
|
204
205
|
|
|
205
206
|
// Not an RTL query
|
|
206
207
|
if (!queryNode || queryNode.type !== "CallExpression") {
|
|
@@ -220,7 +221,7 @@ const create = context => {
|
|
|
220
221
|
// const foo = <query> expect(foo).<matcher>
|
|
221
222
|
[`MemberExpression[object.callee.name=expect][property.name=${alternativeMatchers}][object.arguments.0.type=Identifier]`](node) {
|
|
222
223
|
// Value expression being assigned to the left-hand value
|
|
223
|
-
const rightValueNode = (0, _assignmentAst.getAssignmentForIdentifier)(context, node.object.arguments[0].name);
|
|
224
|
+
const rightValueNode = (0, _assignmentAst.getAssignmentForIdentifier)(context, node, node.object.arguments[0].name);
|
|
224
225
|
|
|
225
226
|
// Not a DTL query
|
|
226
227
|
if (!rightValueNode || rightValueNode.type !== "CallExpression") {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
|
+
var _context = require("../context");
|
|
7
8
|
/**
|
|
8
9
|
* @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
|
|
9
10
|
* @author Ben Monro
|
|
@@ -31,7 +32,7 @@ const create = context => ({
|
|
|
31
32
|
});
|
|
32
33
|
},
|
|
33
34
|
[`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toContain$|toMatch$/]`](node) {
|
|
34
|
-
const sourceCode =
|
|
35
|
+
const sourceCode = (0, _context.getSourceCode)(context);
|
|
35
36
|
context.report({
|
|
36
37
|
node: node.parent,
|
|
37
38
|
message: `Use toHaveAttribute instead of asserting on getAttribute`,
|
|
@@ -41,7 +42,7 @@ const create = context => ({
|
|
|
41
42
|
[`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
|
|
42
43
|
const arg = node.parent.parent.parent.arguments;
|
|
43
44
|
const isNull = arg.length > 0 && arg[0].value === null;
|
|
44
|
-
const sourceCode =
|
|
45
|
+
const sourceCode = (0, _context.getSourceCode)(context);
|
|
45
46
|
context.report({
|
|
46
47
|
node: node.parent,
|
|
47
48
|
message: `Use toHaveAttribute instead of asserting on getAttribute`,
|
|
@@ -68,7 +69,7 @@ const create = context => ({
|
|
|
68
69
|
context.report({
|
|
69
70
|
node: node.parent,
|
|
70
71
|
message: `Use toHaveAttribute instead of asserting on hasAttribute`,
|
|
71
|
-
fix: fixer => [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, `${node.parent.parent.parent.arguments[0].value === false ? "not." : ""}toHaveAttribute`), fixer.replaceText(node.parent.parent.parent.arguments[0],
|
|
72
|
+
fix: fixer => [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, `${node.parent.parent.parent.arguments[0].value === false ? "not." : ""}toHaveAttribute`), fixer.replaceText(node.parent.parent.parent.arguments[0], (0, _context.getSourceCode)(context).getText(node.arguments[0]))]
|
|
72
73
|
});
|
|
73
74
|
} else {
|
|
74
75
|
context.report({
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
7
|
var _assignmentAst = require("../assignment-ast");
|
|
8
|
+
var _context = require("../context");
|
|
8
9
|
/**
|
|
9
10
|
* @fileoverview prefer toHaveClass over checking element className
|
|
10
11
|
* @author Ben Monro
|
|
@@ -40,9 +41,9 @@ const create = context => ({
|
|
|
40
41
|
node: matcher,
|
|
41
42
|
messageId,
|
|
42
43
|
fix(fixer) {
|
|
43
|
-
return [fixer.removeRange([checkedProp.range[1], expectArg.range[1]]), fixer.replaceText(matcher, `${isTruthy ? "" : "not."}toHaveClass`), matcherArg ? fixer.replaceText(matcherArg,
|
|
44
|
+
return [fixer.removeRange([checkedProp.range[1], expectArg.range[1]]), fixer.replaceText(matcher, `${isTruthy ? "" : "not."}toHaveClass`), matcherArg ? fixer.replaceText(matcherArg, (0, _context.getSourceCode)(context).getText(classValue)) : fixer.insertTextBefore((0, _context.getSourceCode)(context).getTokenAfter(matcher, {
|
|
44
45
|
skip: 1
|
|
45
|
-
}),
|
|
46
|
+
}), (0, _context.getSourceCode)(context).getText(classValue))];
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
49
|
},
|
|
@@ -58,7 +59,7 @@ const create = context => ({
|
|
|
58
59
|
fix(fixer) {
|
|
59
60
|
//can't autofix here as it toHaveClass doesn't have a partial matcher / regex for class names.
|
|
60
61
|
if (matcher.name === "toContain") return;
|
|
61
|
-
return [fixer.removeRange([classNameProp.object.range[1], expectArg.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue,
|
|
62
|
+
return [fixer.removeRange([classNameProp.object.range[1], expectArg.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, (0, _context.getSourceCode)(context).getText(classValue))];
|
|
62
63
|
}
|
|
63
64
|
});
|
|
64
65
|
},
|
|
@@ -92,7 +93,7 @@ const create = context => ({
|
|
|
92
93
|
if (checkedProp.name === "classList" && matcher.name !== "toContain") {
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
|
-
return [fixer.removeRange([classNameProp.range[1], checkedProp.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, `${
|
|
96
|
+
return [fixer.removeRange([classNameProp.range[1], checkedProp.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, `${(0, _context.getSourceCode)(context).getText(classValue)}${matcher.name === "toContain" ? "" : ", { exact: true }"}`)];
|
|
96
97
|
}
|
|
97
98
|
});
|
|
98
99
|
},
|
|
@@ -112,7 +113,7 @@ const create = context => ({
|
|
|
112
113
|
messageId,
|
|
113
114
|
fix(fixer) {
|
|
114
115
|
if (matcherArg.name !== "stringContaining") return;
|
|
115
|
-
return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(node.arguments[0], `${
|
|
116
|
+
return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(node.arguments[0], `${(0, _context.getSourceCode)(context).getText(classValue)}`)];
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
119
|
},
|
|
@@ -133,7 +134,7 @@ const create = context => ({
|
|
|
133
134
|
if (className.name === "classList" && matcher.name !== "toContain") {
|
|
134
135
|
return;
|
|
135
136
|
}
|
|
136
|
-
return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, `${
|
|
137
|
+
return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, `${(0, _context.getSourceCode)(context).getText(classValue)}${matcher.name === "toContain" ? "" : ", { exact: true }"}`)];
|
|
137
138
|
}
|
|
138
139
|
});
|
|
139
140
|
},
|
|
@@ -154,7 +155,7 @@ const create = context => ({
|
|
|
154
155
|
node: matcher,
|
|
155
156
|
messageId,
|
|
156
157
|
fix(fixer) {
|
|
157
|
-
return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg,
|
|
158
|
+
return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg, (0, _context.getSourceCode)(context).getText(classValueArg)), fixer.replaceText(classValueArg, `{ exact: true }`)];
|
|
158
159
|
}
|
|
159
160
|
});
|
|
160
161
|
},
|
|
@@ -176,7 +177,7 @@ const create = context => ({
|
|
|
176
177
|
node: matcher,
|
|
177
178
|
messageId,
|
|
178
179
|
fix(fixer) {
|
|
179
|
-
return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg,
|
|
180
|
+
return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg, (0, _context.getSourceCode)(context).getText(classValueArg)), fixer.replaceText(classValueArg, `{ exact: true }`)];
|
|
180
181
|
}
|
|
181
182
|
});
|
|
182
183
|
},
|
|
@@ -198,7 +199,7 @@ const create = context => ({
|
|
|
198
199
|
node: matcher,
|
|
199
200
|
messageId,
|
|
200
201
|
fix(fixer) {
|
|
201
|
-
return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg,
|
|
202
|
+
return [fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classArg, (0, _context.getSourceCode)(context).getText(classValueArg)), fixer.removeRange([classArg.range[1], classValue.range[1]])];
|
|
202
203
|
}
|
|
203
204
|
});
|
|
204
205
|
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
|
+
var _context = require("../context");
|
|
7
8
|
/**
|
|
8
9
|
* @fileoverview prefer toHaveStyle over checking element style
|
|
9
10
|
* @author Ben Monro
|
|
@@ -27,10 +28,10 @@ const create = context => {
|
|
|
27
28
|
if (styleName.type === "Literal") {
|
|
28
29
|
return camelCase(styleName.value);
|
|
29
30
|
}
|
|
30
|
-
return `[${
|
|
31
|
+
return `[${(0, _context.getSourceCode)(context).getText(styleName)}]`;
|
|
31
32
|
}
|
|
32
33
|
function getReplacementStyleParam(styleName, styleValue) {
|
|
33
|
-
return styleName.type === "Literal" ? `{${camelCase(styleName.value)}: ${context.getSourceCode().getText(styleValue)}}` : `${
|
|
34
|
+
return styleName.type === "Literal" ? `{${camelCase(styleName.value)}: ${context.getSourceCode().getText(styleValue)}}` : `${(0, _context.getSourceCode)(context).getText(styleName).slice(0, -1)}: ${styleValue.type === "TemplateLiteral" ? (0, _context.getSourceCode)(context).getText(styleValue).substring(1) : `${styleValue.value}\``}`;
|
|
34
35
|
}
|
|
35
36
|
return {
|
|
36
37
|
//expect(el.style.foo).toBe("bar");
|
|
@@ -67,7 +68,7 @@ const create = context => {
|
|
|
67
68
|
node: node.property,
|
|
68
69
|
message: "Use toHaveStyle instead of asserting on element style",
|
|
69
70
|
fix(fixer) {
|
|
70
|
-
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleName, styleName.type === "Literal" ? `{${camelCase(styleName.value)}: expect.anything()}` :
|
|
71
|
+
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleName, styleName.type === "Literal" ? `{${camelCase(styleName.value)}: expect.anything()}` : (0, _context.getSourceCode)(context).getText(styleName))];
|
|
71
72
|
}
|
|
72
73
|
});
|
|
73
74
|
},
|
|
@@ -79,7 +80,7 @@ const create = context => {
|
|
|
79
80
|
node: node.property,
|
|
80
81
|
message: "Use toHaveStyle instead of asserting on element style",
|
|
81
82
|
fix(fixer) {
|
|
82
|
-
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleName, styleName.type === "Literal" ? `{${camelCase(styleName.value)}: expect.anything()}` :
|
|
83
|
+
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleName, styleName.type === "Literal" ? `{${camelCase(styleName.value)}: expect.anything()}` : (0, _context.getSourceCode)(context).getText(styleName))];
|
|
83
84
|
}
|
|
84
85
|
});
|
|
85
86
|
},
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
|
+
var _context = require("../context");
|
|
7
8
|
/**
|
|
8
9
|
* @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
|
|
9
10
|
* @author Ben Monro
|
|
@@ -21,7 +22,7 @@ const meta = exports.meta = {
|
|
|
21
22
|
const create = context => ({
|
|
22
23
|
[`MemberExpression[property.name='textContent'][parent.callee.name='expect'][parent.parent.property.name=/toContain$|toMatch$/]`](node) {
|
|
23
24
|
const expectedArg = node.parent.parent.parent.arguments[0];
|
|
24
|
-
const expectedArgSource =
|
|
25
|
+
const expectedArgSource = (0, _context.getSourceCode)(context).getText(expectedArg);
|
|
25
26
|
context.report({
|
|
26
27
|
node: node.parent,
|
|
27
28
|
message: `Use toHaveTextContent instead of asserting on DOM node attributes`,
|
|
@@ -46,7 +47,7 @@ const create = context => ({
|
|
|
46
47
|
},
|
|
47
48
|
[`MemberExpression[property.name='textContent'][parent.callee.name='expect'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toContain$|toMatch$/]`](node) {
|
|
48
49
|
const expectedArg = node.parent.parent.parent.parent.arguments[0];
|
|
49
|
-
const expectedArgSource =
|
|
50
|
+
const expectedArgSource = (0, _context.getSourceCode)(context).getText(expectedArg);
|
|
50
51
|
context.report({
|
|
51
52
|
node: node.parent,
|
|
52
53
|
message: `Use toHaveTextContent instead of asserting on DOM node attributes`,
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.meta = exports.create = void 0;
|
|
7
7
|
var _assignmentAst = require("../assignment-ast");
|
|
8
|
+
var _context = require("../context");
|
|
8
9
|
/**
|
|
9
10
|
* @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
|
|
10
11
|
* @author Ben Monro
|
|
@@ -49,7 +50,7 @@ const create = context => {
|
|
|
49
50
|
messageId,
|
|
50
51
|
node,
|
|
51
52
|
fix(fixer) {
|
|
52
|
-
return [fixer.remove(
|
|
53
|
+
return [fixer.remove((0, _context.getSourceCode)(context).getTokenBefore(valueProp)), fixer.remove(valueProp), fixer.replaceText(matcher, "toHaveValue")];
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
}
|
|
@@ -66,7 +67,7 @@ const create = context => {
|
|
|
66
67
|
messageId,
|
|
67
68
|
node,
|
|
68
69
|
fix(fixer) {
|
|
69
|
-
return [fixer.removeRange([
|
|
70
|
+
return [fixer.removeRange([(0, _context.getSourceCode)(context).getTokenBefore(valueProp).range[0], valueProp.range[1]]), fixer.replaceText(matcher, "toHaveValue")];
|
|
70
71
|
}
|
|
71
72
|
});
|
|
72
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-dom",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -52,11 +52,12 @@
|
|
|
52
52
|
"eslint-remote-tester": "^3.0.0",
|
|
53
53
|
"eslint-remote-tester-repositories": "^1.0.1",
|
|
54
54
|
"kcd-scripts": "^12.0.0",
|
|
55
|
+
"semver": "^7.6.0",
|
|
55
56
|
"typescript": "^5.1.3"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
|
-
"@testing-library/dom": "^8.0.0 || ^9.0.0",
|
|
59
|
-
"eslint": "^6.8.0 || ^7.0.0 || ^8.0.0"
|
|
59
|
+
"@testing-library/dom": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
60
|
+
"eslint": "^6.8.0 || ^7.0.0 || ^8.0.0 || ^9.0.0"
|
|
60
61
|
},
|
|
61
62
|
"peerDependenciesMeta": {
|
|
62
63
|
"@testing-library/dom": {
|