eslint-plugin-jest-dom 4.0.1 → 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.
- package/README.md +21 -22
- package/dist/assignment-ast.js +2 -17
- package/dist/createBannedAttributeRule.js +2 -17
- package/dist/index.js +7 -9
- package/dist/queries.js +0 -2
- package/dist/rules/prefer-checked.js +1 -3
- package/dist/rules/prefer-empty.js +1 -19
- package/dist/rules/prefer-enabled-disabled.js +1 -3
- package/dist/rules/prefer-focus.js +7 -12
- package/dist/rules/prefer-in-document.js +26 -42
- package/dist/rules/prefer-required.js +1 -3
- package/dist/rules/prefer-to-have-attribute.js +2 -10
- package/dist/rules/prefer-to-have-class.js +22 -36
- package/dist/rules/prefer-to-have-style.js +22 -41
- package/dist/rules/prefer-to-have-text-content.js +1 -7
- package/dist/rules/prefer-to-have-value.js +2 -16
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -92,27 +92,27 @@ module.exports = {
|
|
|
92
92
|
|
|
93
93
|
## Supported Rules
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
| Name
|
|
102
|
-
|
|
|
103
|
-
| [prefer-checked](
|
|
104
|
-
| [prefer-empty](
|
|
105
|
-
| [prefer-enabled-disabled](
|
|
106
|
-
| [prefer-focus](
|
|
107
|
-
| [prefer-in-document](
|
|
108
|
-
| [prefer-required](
|
|
109
|
-
| [prefer-to-have-attribute](
|
|
110
|
-
| [prefer-to-have-class](
|
|
111
|
-
| [prefer-to-have-style](
|
|
112
|
-
| [prefer-to-have-text-content](
|
|
113
|
-
| [prefer-to-have-value](
|
|
114
|
-
|
|
115
|
-
<!--
|
|
95
|
+
<!-- begin auto-generated rules list -->
|
|
96
|
+
|
|
97
|
+
💼 Configurations enabled in.\
|
|
98
|
+
✅ Set in the `recommended` configuration.\
|
|
99
|
+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
100
|
+
|
|
101
|
+
| Name | Description | 💼 | 🔧 |
|
|
102
|
+
| :----------------------------------------------------------------------- | :-------------------------------------------------------------------- | :- | :- |
|
|
103
|
+
| [prefer-checked](docs/rules/prefer-checked.md) | prefer toBeChecked over checking attributes | ✅ | 🔧 |
|
|
104
|
+
| [prefer-empty](docs/rules/prefer-empty.md) | Prefer toBeEmpty over checking innerHTML | ✅ | 🔧 |
|
|
105
|
+
| [prefer-enabled-disabled](docs/rules/prefer-enabled-disabled.md) | prefer toBeDisabled or toBeEnabled over checking attributes | ✅ | 🔧 |
|
|
106
|
+
| [prefer-focus](docs/rules/prefer-focus.md) | prefer toHaveFocus over checking document.activeElement | ✅ | 🔧 |
|
|
107
|
+
| [prefer-in-document](docs/rules/prefer-in-document.md) | Prefer .toBeInTheDocument() for asserting the existence of a DOM node | ✅ | 🔧 |
|
|
108
|
+
| [prefer-required](docs/rules/prefer-required.md) | prefer toBeRequired over checking properties | ✅ | 🔧 |
|
|
109
|
+
| [prefer-to-have-attribute](docs/rules/prefer-to-have-attribute.md) | prefer toHaveAttribute over checking getAttribute/hasAttribute | ✅ | 🔧 |
|
|
110
|
+
| [prefer-to-have-class](docs/rules/prefer-to-have-class.md) | prefer toHaveClass over checking element className | ✅ | 🔧 |
|
|
111
|
+
| [prefer-to-have-style](docs/rules/prefer-to-have-style.md) | prefer toHaveStyle over checking element style | ✅ | 🔧 |
|
|
112
|
+
| [prefer-to-have-text-content](docs/rules/prefer-to-have-text-content.md) | Prefer toHaveTextContent over checking element.textContent | ✅ | 🔧 |
|
|
113
|
+
| [prefer-to-have-value](docs/rules/prefer-to-have-value.md) | prefer toHaveValue over checking element.value | ✅ | 🔧 |
|
|
114
|
+
|
|
115
|
+
<!-- end auto-generated rules list -->
|
|
116
116
|
|
|
117
117
|
## Issues
|
|
118
118
|
|
|
@@ -196,7 +196,6 @@ MIT
|
|
|
196
196
|
[coc]: https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/other/CODE_OF_CONDUCT.md
|
|
197
197
|
[emojis]: https://github.com/all-contributors/all-contributors#emoji-key
|
|
198
198
|
[all-contributors]: https://github.com/all-contributors/all-contributors
|
|
199
|
-
[all-contributors-badge]: https://img.shields.io/github/all-contributors/testing-library/eslint-plugin-jest-dom?color=orange&style=flat-square
|
|
200
199
|
[bugs]: https://github.com/testing-library/eslint-plugin-jest-dom/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug
|
|
201
200
|
[requests]: https://github.com/testing-library/eslint-plugin-jest-dom/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement
|
|
202
201
|
[good-first-issue]: https://github.com/testing-library/eslint-plugin-jest-dom/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement+label%3A%22good+first+issue%22
|
package/dist/assignment-ast.js
CHANGED
|
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getAssignmentForIdentifier = getAssignmentForIdentifier;
|
|
7
7
|
exports.getInnerNodeFrom = getInnerNodeFrom;
|
|
8
8
|
exports.getQueryNodeFrom = getQueryNodeFrom;
|
|
9
|
-
|
|
10
9
|
var _queries = require("./queries");
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* Gets the inner relevant node (CallExpression, Identity, et al.) given a generic expression node
|
|
14
12
|
* await someAsyncFunc() => someAsyncFunc()
|
|
@@ -21,17 +19,15 @@ function getInnerNodeFrom(expression) {
|
|
|
21
19
|
switch (expression.type) {
|
|
22
20
|
case "TSAsExpression":
|
|
23
21
|
return getInnerNodeFrom(expression.expression);
|
|
24
|
-
|
|
25
22
|
case "AwaitExpression":
|
|
26
23
|
return getInnerNodeFrom(expression.argument);
|
|
27
|
-
|
|
28
24
|
case "MemberExpression":
|
|
29
25
|
return getInnerNodeFrom(expression.object);
|
|
30
|
-
|
|
31
26
|
default:
|
|
32
27
|
return expression;
|
|
33
28
|
}
|
|
34
29
|
}
|
|
30
|
+
|
|
35
31
|
/**
|
|
36
32
|
* Get the node corresponding to the latest assignment to a variable named `identifierName`
|
|
37
33
|
*
|
|
@@ -39,14 +35,11 @@ function getInnerNodeFrom(expression) {
|
|
|
39
35
|
* @param {String} identifierName - Name of an identifier
|
|
40
36
|
* @returns {Object} - A node, possibly undefined
|
|
41
37
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
38
|
function getAssignmentForIdentifier(context, identifierName) {
|
|
45
39
|
const variable = context.getScope().set.get(identifierName);
|
|
46
40
|
if (!variable) return;
|
|
47
41
|
const init = variable.defs[0].node.init;
|
|
48
42
|
let assignmentNode;
|
|
49
|
-
|
|
50
43
|
if (init) {
|
|
51
44
|
// let foo = bar;
|
|
52
45
|
assignmentNode = getInnerNodeFrom(init);
|
|
@@ -54,16 +47,14 @@ function getAssignmentForIdentifier(context, identifierName) {
|
|
|
54
47
|
// let foo;
|
|
55
48
|
// foo = bar;
|
|
56
49
|
const assignmentRef = variable.references.reverse().find(ref => !!ref.writeExpr);
|
|
57
|
-
|
|
58
50
|
if (!assignmentRef) {
|
|
59
51
|
return;
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
assignmentNode = getInnerNodeFrom(assignmentRef.writeExpr);
|
|
63
54
|
}
|
|
64
|
-
|
|
65
55
|
return assignmentNode;
|
|
66
56
|
}
|
|
57
|
+
|
|
67
58
|
/**
|
|
68
59
|
* get query node, arg and isDTLQuery flag for a given node. useful for rules that you only
|
|
69
60
|
* want to apply to dom elements.
|
|
@@ -72,11 +63,8 @@ function getAssignmentForIdentifier(context, identifierName) {
|
|
|
72
63
|
* @param {Object} nodeWithValueProp - AST Node to get the query from
|
|
73
64
|
* @returns {Object} - Object with query, queryArg & isDTLQuery
|
|
74
65
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
66
|
function getQueryNodeFrom(context, nodeWithValueProp) {
|
|
78
67
|
const queryNode = nodeWithValueProp.type === "Identifier" ? getAssignmentForIdentifier(context, nodeWithValueProp.name) : getInnerNodeFrom(nodeWithValueProp);
|
|
79
|
-
|
|
80
68
|
if (!queryNode || !queryNode.callee) {
|
|
81
69
|
return {
|
|
82
70
|
isDTLQuery: false,
|
|
@@ -84,12 +72,9 @@ function getQueryNodeFrom(context, nodeWithValueProp) {
|
|
|
84
72
|
queryArg: null
|
|
85
73
|
};
|
|
86
74
|
}
|
|
87
|
-
|
|
88
75
|
const query = queryNode.callee.name || queryNode.callee.property && queryNode.callee.property.name;
|
|
89
76
|
const queryArg = queryNode.arguments[0] && queryNode.arguments[0].value;
|
|
90
|
-
|
|
91
77
|
const isDTLQuery = _queries.queries.includes(query);
|
|
92
|
-
|
|
93
78
|
return {
|
|
94
79
|
queryArg,
|
|
95
80
|
query,
|
|
@@ -4,25 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _assignmentAst = require("./assignment-ast");
|
|
9
|
-
|
|
10
8
|
var _default = ({
|
|
11
9
|
preferred,
|
|
12
10
|
negatedPreferred,
|
|
13
11
|
attributes
|
|
14
12
|
}) => context => {
|
|
15
13
|
const getCorrectFunctionFor = (node, negated = false) => (node.arguments.length === 1 || node.arguments[1].value === true || node.arguments[1].type !== "Literal" || typeof node.arguments[1].value === "string" && node.arguments[1].value.toLowerCase() === "true" || node.arguments[1].value === "") && !negated ? preferred : negatedPreferred;
|
|
14
|
+
const isBannedArg = node => node.arguments.length && attributes.some(attr => attr === node.arguments[0].value);
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
//expect(el).not.toBeEnabled() => expect(el).toBeDisabled()
|
|
20
17
|
return {
|
|
21
18
|
[`CallExpression[callee.property.name=/${preferred}|${negatedPreferred}/][callee.object.property.name='not'][callee.object.object.callee.name='expect']`](node) {
|
|
22
19
|
if (!negatedPreferred.startsWith("toBe")) {
|
|
23
20
|
return;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
const incorrectFunction = node.callee.property.name;
|
|
27
23
|
const correctFunction = incorrectFunction === preferred ? negatedPreferred : preferred;
|
|
28
24
|
context.report({
|
|
@@ -31,13 +27,11 @@ var _default = ({
|
|
|
31
27
|
fix: fixer => fixer.replaceTextRange([node.callee.object.property.range[0], node.range[1]], `${correctFunction}()`)
|
|
32
28
|
});
|
|
33
29
|
},
|
|
34
|
-
|
|
35
30
|
//expect(getByText('foo').<attribute>).toBeTruthy()
|
|
36
31
|
"CallExpression[callee.property.name=/toBe(Truthy|Falsy)?|toEqual/][callee.object.callee.name='expect']"(node) {
|
|
37
32
|
if (!node.callee.object.arguments.length) {
|
|
38
33
|
return;
|
|
39
34
|
}
|
|
40
|
-
|
|
41
35
|
const {
|
|
42
36
|
arguments: [{
|
|
43
37
|
object,
|
|
@@ -49,11 +43,9 @@ var _default = ({
|
|
|
49
43
|
} = node.callee.object;
|
|
50
44
|
const matcher = node.callee.property.name;
|
|
51
45
|
const matcherArg = node.arguments.length && node.arguments[0].value;
|
|
52
|
-
|
|
53
46
|
if (!attributes.some(attr => attr === name)) {
|
|
54
47
|
return;
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
const {
|
|
58
50
|
isDTLQuery
|
|
59
51
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
|
@@ -66,12 +58,10 @@ var _default = ({
|
|
|
66
58
|
fix: fixer => [fixer.removeRange([object.range[1], property.range[1]]), fixer.replaceTextRange([node.callee.property.range[0], node.range[1]], `${correctFunction}()`)]
|
|
67
59
|
});
|
|
68
60
|
},
|
|
69
|
-
|
|
70
61
|
"CallExpression[callee.property.name=/toHaveProperty|toHaveAttribute/][callee.object.property.name='not'][callee.object.object.callee.name='expect']"(node) {
|
|
71
62
|
if (!isBannedArg(node)) {
|
|
72
63
|
return;
|
|
73
64
|
}
|
|
74
|
-
|
|
75
65
|
const arg = node.arguments[0].value;
|
|
76
66
|
const correctFunction = getCorrectFunctionFor(node, true);
|
|
77
67
|
const incorrectFunction = node.callee.property.name;
|
|
@@ -81,12 +71,10 @@ var _default = ({
|
|
|
81
71
|
fix: fixer => fixer.replaceTextRange([node.callee.object.property.range[0], node.range[1]], `${correctFunction}()`)
|
|
82
72
|
});
|
|
83
73
|
},
|
|
84
|
-
|
|
85
74
|
"CallExpression[callee.object.callee.name='expect'][callee.property.name=/toHaveProperty|toHaveAttribute/]"(node) {
|
|
86
75
|
if (!isBannedArg(node)) {
|
|
87
76
|
return;
|
|
88
77
|
}
|
|
89
|
-
|
|
90
78
|
const {
|
|
91
79
|
isDTLQuery
|
|
92
80
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
|
@@ -105,13 +93,10 @@ var _default = ({
|
|
|
105
93
|
if (node.arguments.length === 1 || secondArgIsLiteral) {
|
|
106
94
|
return [fixer.replaceTextRange([node.callee.property.range[0], node.range[1]], `${correctFunction}()`)];
|
|
107
95
|
}
|
|
108
|
-
|
|
109
96
|
return null;
|
|
110
97
|
}
|
|
111
98
|
});
|
|
112
99
|
}
|
|
113
|
-
|
|
114
100
|
};
|
|
115
101
|
};
|
|
116
|
-
|
|
117
102
|
exports.default = _default;
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
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.rules = exports.generateRecommendedConfig = exports.generateAllRulesConfig = exports.configs = void 0;
|
|
9
|
-
|
|
10
8
|
var _requireindex = _interopRequireDefault(require("requireindex"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* @fileoverview lint rules for use with jest-dom
|
|
14
11
|
* @author Ben Monro
|
|
15
12
|
*/
|
|
13
|
+
|
|
16
14
|
//------------------------------------------------------------------------------
|
|
17
15
|
// Requirements
|
|
18
16
|
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
19
18
|
//------------------------------------------------------------------------------
|
|
20
19
|
// Plugin Definition
|
|
21
20
|
//------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
22
|
// import all rules in src/rules
|
|
23
23
|
const rules = (0, _requireindex.default)(`${__dirname}/rules`);
|
|
24
24
|
exports.rules = rules;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const generateRecommendedConfig = allRules => Object.entries(allRules).reduce((memo, [name, rule]) => ({
|
|
26
|
+
...memo,
|
|
27
27
|
...(rule.meta.docs.recommended ? {
|
|
28
28
|
[`jest-dom/${name}`]: "error"
|
|
29
29
|
} : {})
|
|
30
30
|
}), {});
|
|
31
|
-
|
|
32
31
|
exports.generateRecommendedConfig = generateRecommendedConfig;
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const generateAllRulesConfig = allRules => Object.entries(allRules).reduce((memo, [name]) => ({
|
|
33
|
+
...memo,
|
|
35
34
|
...{
|
|
36
35
|
[`jest-dom/${name}`]: "error"
|
|
37
36
|
}
|
|
38
37
|
}), {});
|
|
39
|
-
|
|
40
38
|
exports.generateAllRulesConfig = generateAllRulesConfig;
|
|
41
39
|
const configs = {
|
|
42
40
|
recommended: {
|
package/dist/queries.js
CHANGED
|
@@ -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 toBeChecked over checking attributes",
|
|
@@ -4,11 +4,11 @@ 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 toBeEmpty over checking innerHTML
|
|
10
9
|
* @author Ben Monro
|
|
11
10
|
*/
|
|
11
|
+
|
|
12
12
|
const meta = {
|
|
13
13
|
docs: {
|
|
14
14
|
description: "Prefer toBeEmpty over checking innerHTML",
|
|
@@ -17,15 +17,12 @@ const meta = {
|
|
|
17
17
|
url: "prefer-empty"
|
|
18
18
|
},
|
|
19
19
|
fixable: "code" // or "code" or "whitespace"
|
|
20
|
-
|
|
21
20
|
};
|
|
22
21
|
exports.meta = meta;
|
|
23
|
-
|
|
24
22
|
const create = context => {
|
|
25
23
|
function isNonEmptyStringOrTemplateLiteral(node) {
|
|
26
24
|
return !['""', "''", "``", "null"].includes(context.getSourceCode().getText(node));
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
return {
|
|
30
27
|
[`BinaryExpression[left.property.name='innerHTML'][right.value=''][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
|
|
31
28
|
context.report({
|
|
@@ -35,7 +32,6 @@ const create = context => {
|
|
|
35
32
|
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])]
|
|
36
33
|
});
|
|
37
34
|
},
|
|
38
|
-
|
|
39
35
|
[`BinaryExpression[left.property.name='firstChild'][right.value=null][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
|
|
40
36
|
context.report({
|
|
41
37
|
node,
|
|
@@ -44,35 +40,28 @@ const create = context => {
|
|
|
44
40
|
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])]
|
|
45
41
|
});
|
|
46
42
|
},
|
|
47
|
-
|
|
48
43
|
[`MemberExpression[property.name = 'innerHTML'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) {
|
|
49
44
|
const args = node.parent.parent.parent.arguments[0];
|
|
50
|
-
|
|
51
45
|
if (isNonEmptyStringOrTemplateLiteral(args)) {
|
|
52
46
|
return;
|
|
53
47
|
}
|
|
54
|
-
|
|
55
48
|
context.report({
|
|
56
49
|
node,
|
|
57
50
|
message: "Use toBeEmptyDOMElement instead of checking inner html.",
|
|
58
51
|
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])]
|
|
59
52
|
});
|
|
60
53
|
},
|
|
61
|
-
|
|
62
54
|
[`MemberExpression[property.name='innerHTML'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']`](node) {
|
|
63
55
|
const args = node.parent.parent.parent.parent.arguments[0];
|
|
64
|
-
|
|
65
56
|
if (isNonEmptyStringOrTemplateLiteral(args)) {
|
|
66
57
|
return;
|
|
67
58
|
}
|
|
68
|
-
|
|
69
59
|
context.report({
|
|
70
60
|
node,
|
|
71
61
|
message: "Use toBeEmptyDOMElement instead of checking inner html.",
|
|
72
62
|
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.parent.arguments[0])]
|
|
73
63
|
});
|
|
74
64
|
},
|
|
75
|
-
|
|
76
65
|
[`MemberExpression[property.name = 'firstChild'][parent.callee.name = 'expect'][parent.parent.property.name = /toBeNull$/]`](node) {
|
|
77
66
|
context.report({
|
|
78
67
|
node,
|
|
@@ -80,19 +69,16 @@ const create = context => {
|
|
|
80
69
|
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement")]
|
|
81
70
|
});
|
|
82
71
|
},
|
|
83
|
-
|
|
84
72
|
[`MemberExpression[property.name='firstChild'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']`](node) {
|
|
85
73
|
if (node.parent.parent.parent.parent.arguments[0].value !== null) {
|
|
86
74
|
return;
|
|
87
75
|
}
|
|
88
|
-
|
|
89
76
|
context.report({
|
|
90
77
|
node,
|
|
91
78
|
message: "Use toBeEmptyDOMElement instead of checking inner html.",
|
|
92
79
|
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.parent.arguments[0])]
|
|
93
80
|
});
|
|
94
81
|
},
|
|
95
|
-
|
|
96
82
|
[`MemberExpression[property.name='firstChild'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBeNull$/][parent.parent.object.callee.name='expect']`](node) {
|
|
97
83
|
context.report({
|
|
98
84
|
node,
|
|
@@ -100,20 +86,16 @@ const create = context => {
|
|
|
100
86
|
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement")]
|
|
101
87
|
});
|
|
102
88
|
},
|
|
103
|
-
|
|
104
89
|
[`MemberExpression[property.name = 'firstChild'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) {
|
|
105
90
|
if (node.parent.parent.parent.arguments[0].value !== null) {
|
|
106
91
|
return;
|
|
107
92
|
}
|
|
108
|
-
|
|
109
93
|
context.report({
|
|
110
94
|
node,
|
|
111
95
|
message: "Use toBeEmptyDOMElement instead of checking inner html.",
|
|
112
96
|
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])]
|
|
113
97
|
});
|
|
114
98
|
}
|
|
115
|
-
|
|
116
99
|
};
|
|
117
100
|
};
|
|
118
|
-
|
|
119
101
|
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 toBeDisabled or toBeEnabled over checking attributes",
|
|
@@ -4,14 +4,17 @@ 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 toHaveFocus over checking activeElementa
|
|
10
9
|
* @author Ben Monro
|
|
11
10
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
|
|
12
|
+
const variantsOfDoc = [
|
|
13
|
+
// document:
|
|
14
|
+
`[object.name=document]`,
|
|
15
|
+
// window.document || global.document:
|
|
16
|
+
`[object.object.name=/(global|window)$/][object.property.name=document]`,
|
|
17
|
+
// global.window.document:
|
|
15
18
|
`[object.object.object.name='global'][object.object.property.name='window'][object.property.name=document]`];
|
|
16
19
|
const meta = {
|
|
17
20
|
docs: {
|
|
@@ -23,7 +26,6 @@ const meta = {
|
|
|
23
26
|
fixable: "code"
|
|
24
27
|
};
|
|
25
28
|
exports.meta = meta;
|
|
26
|
-
|
|
27
29
|
const create = context => ({
|
|
28
30
|
[variantsOfDoc.map(variant => `MemberExpression${variant}[property.name='activeElement'][parent.parent.object.callee.name='expect'][parent.parent.property.name='not'][parent.parent.parent.property.name=/to(Be|(Strict)?Equal)$/]`).join(", ")](node) {
|
|
29
31
|
const element = node.parent.parent.parent.parent.callee.parent.arguments[0];
|
|
@@ -35,12 +37,10 @@ const create = context => ({
|
|
|
35
37
|
if (element.name) {
|
|
36
38
|
return [fixer.replaceText(node, element.name), fixer.remove(element), fixer.replaceText(matcher, "toHaveFocus")];
|
|
37
39
|
}
|
|
38
|
-
|
|
39
40
|
return [fixer.removeRange([node.range[0], element.range[0]]), fixer.insertTextAfterRange([element.range[1], element.range[1] + 1], ".not.toHaveFocus()")];
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
},
|
|
43
|
-
|
|
44
44
|
[variantsOfDoc.map(variant => `MemberExpression${variant}[property.name='activeElement'][parent.callee.object.object.callee.name='expect'][parent.callee.property.name=/to(Be|(Strict)?Equal)$/]`).join(", ")](node) {
|
|
45
45
|
const matcher = node.parent.callee.property;
|
|
46
46
|
context.report({
|
|
@@ -49,7 +49,6 @@ const create = context => ({
|
|
|
49
49
|
fix: fixer => [fixer.remove(node), fixer.replaceText(matcher, "toHaveFocus")]
|
|
50
50
|
});
|
|
51
51
|
},
|
|
52
|
-
|
|
53
52
|
[variantsOfDoc.map(variant => `MemberExpression${variant}[property.name='activeElement'][parent.callee.name='expect'][parent.parent.property.name=/to(Be|(Strict)?Equal)$/]`).join(", ")](node) {
|
|
54
53
|
const element = node.parent.parent.parent.arguments[0];
|
|
55
54
|
const matcher = node.parent.parent.property;
|
|
@@ -60,12 +59,10 @@ const create = context => ({
|
|
|
60
59
|
if (!element.name) {
|
|
61
60
|
return [fixer.removeRange([node.range[0], element.range[0]]), fixer.insertTextAfterRange([element.range[1], element.range[1] + 1], ".toHaveFocus()")];
|
|
62
61
|
}
|
|
63
|
-
|
|
64
62
|
return [fixer.replaceText(node, element.name), fixer.remove(element), fixer.replaceText(matcher, "toHaveFocus")];
|
|
65
63
|
}
|
|
66
64
|
});
|
|
67
65
|
},
|
|
68
|
-
|
|
69
66
|
[variantsOfDoc.map(variant => `MemberExpression${variant}[property.name='activeElement'][parent.callee.object.callee.name='expect'][parent.callee.property.name=/to(Be|(Strict)?Equal)$/]`).join(", ")](node) {
|
|
70
67
|
const matcher = node.parent.callee.property;
|
|
71
68
|
context.report({
|
|
@@ -74,7 +71,5 @@ const create = context => ({
|
|
|
74
71
|
fix: fixer => [fixer.remove(node), fixer.replaceText(matcher, "toHaveFocus")]
|
|
75
72
|
});
|
|
76
73
|
}
|
|
77
|
-
|
|
78
74
|
});
|
|
79
|
-
|
|
80
75
|
exports.create = create;
|