eslint-plugin-jest-dom 5.7.1 → 5.8.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/dist/assignment-ast.js +1 -3
- package/dist/context.js +1 -3
- package/dist/createBannedAttributeRule.js +26 -13
- package/dist/index.js +2 -4
- package/dist/queries.js +1 -3
- package/dist/rules/prefer-checked.js +4 -6
- package/dist/rules/prefer-empty.js +5 -7
- package/dist/rules/prefer-enabled-disabled.js +2 -4
- package/dist/rules/prefer-focus.js +1 -3
- package/dist/rules/prefer-in-document.js +1 -3
- package/dist/rules/prefer-pressed.js +4 -6
- package/dist/rules/prefer-required.js +2 -4
- package/dist/rules/prefer-to-have-attribute.js +1 -3
- package/dist/rules/prefer-to-have-class.js +1 -3
- package/dist/rules/prefer-to-have-style.js +1 -3
- package/dist/rules/prefer-to-have-text-content.js +1 -3
- package/dist/rules/prefer-to-have-value.js +37 -4
- package/package.json +11 -53
package/dist/assignment-ast.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
exports.getAssignmentForIdentifier = getAssignmentForIdentifier;
|
|
7
5
|
exports.getInnerNodeFrom = getInnerNodeFrom;
|
|
8
6
|
exports.getQueryNodeFrom = getQueryNodeFrom;
|
package/dist/context.js
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
exports.default = void 0;
|
|
7
5
|
var _assignmentAst = require("./assignment-ast");
|
|
8
6
|
var _default = ({
|
|
9
7
|
preferred,
|
|
10
8
|
negatedPreferred,
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
mixedPreferred,
|
|
10
|
+
attributes
|
|
13
11
|
}) => context => {
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Returns the value of the second argument of the given node, if it's a string literal
|
|
14
|
+
* or otherwise null
|
|
15
|
+
*
|
|
16
|
+
* @param node
|
|
17
|
+
*
|
|
18
|
+
* @return {string | null}
|
|
19
|
+
*/
|
|
20
|
+
const findSecondStringLiteralArgumentValue = node => node.arguments.length >= 2 && node.arguments[1].type === "Literal" && typeof node.arguments[1].value === "string" && node.arguments[1].value || null;
|
|
21
|
+
const getCorrectFunctionFor = (node, negated = false) => {
|
|
22
|
+
const value = findSecondStringLiteralArgumentValue(node);
|
|
23
|
+
const isMixed = mixedPreferred && (value || "").toLowerCase() === "mixed";
|
|
24
|
+
if (isMixed) {
|
|
25
|
+
return negated ? `not.${mixedPreferred}` : mixedPreferred;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// use the negated preference if we're _not_ using a truthy value,
|
|
29
|
+
// or we have been told we're negated // todo: this might be a bug?
|
|
30
|
+
if (negated || !(node.arguments.length === 1 || node.arguments[1].value === true || node.arguments[1].type !== "Literal" || (value || "").toLowerCase() === "true" || node.arguments[1].value === "")) {
|
|
31
|
+
return negatedPreferred;
|
|
32
|
+
}
|
|
33
|
+
return preferred;
|
|
34
|
+
};
|
|
16
35
|
const isBannedArg = node => node.arguments.length && attributes.some(attr => attr === node.arguments[0].value);
|
|
17
36
|
|
|
18
37
|
//expect(el).not.toBeEnabled() => expect(el).toBeDisabled()
|
|
@@ -64,9 +83,6 @@ var _default = ({
|
|
|
64
83
|
if (!isBannedArg(node)) {
|
|
65
84
|
return;
|
|
66
85
|
}
|
|
67
|
-
if (isExcludedValue(node)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
86
|
const correctFunction = getCorrectFunctionFor(node, true);
|
|
71
87
|
const incorrectFunction = node.callee.property.name;
|
|
72
88
|
const message = `Use ${correctFunction}() instead of not.${incorrectFunction}(${node.arguments.map(({
|
|
@@ -83,9 +99,6 @@ var _default = ({
|
|
|
83
99
|
if (!isBannedArg(node)) {
|
|
84
100
|
return;
|
|
85
101
|
}
|
|
86
|
-
if (isExcludedValue(node)) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
102
|
const {
|
|
90
103
|
isDTLQuery
|
|
91
104
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
7
4
|
exports.rules = exports.default = exports.configs = void 0;
|
|
8
5
|
var _requireindex = _interopRequireDefault(require("requireindex"));
|
|
9
6
|
var _package = require("../package.json");
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
8
|
/**
|
|
11
9
|
* @fileoverview lint rules for use with jest-dom
|
|
12
10
|
* @author Ben Monro
|
package/dist/queries.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
exports.queries = void 0;
|
|
7
5
|
let theQueries = ["findAllBy", "findBy", "getAllBy", "getBy", "queryAllBy", "queryBy"].flatMap(prefix => ["AltText", "DisplayValue", "LabelText", "PlaceholderText", "Role", "TestId", "Text", "Title"].map(element => `${prefix}${element}`));
|
|
8
6
|
(() => {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
7
4
|
exports.meta = exports.create = void 0;
|
|
8
5
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
7
|
/**
|
|
10
8
|
* @fileoverview prefer toBeDisabled or toBeEnabled over attribute checks
|
|
11
9
|
* @author Ben Monro
|
|
@@ -23,6 +21,6 @@ const meta = exports.meta = {
|
|
|
23
21
|
const create = exports.create = (0, _createBannedAttributeRule.default)({
|
|
24
22
|
preferred: "toBeChecked",
|
|
25
23
|
negatedPreferred: "not.toBeChecked",
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
mixedPreferred: "toBePartiallyChecked",
|
|
25
|
+
attributes: ["checked", "aria-checked"]
|
|
28
26
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
exports.meta = exports.create = void 0;
|
|
7
5
|
var _context = require("../context");
|
|
8
6
|
/**
|
|
@@ -28,16 +26,16 @@ const create = context => {
|
|
|
28
26
|
context.report({
|
|
29
27
|
node,
|
|
30
28
|
message: "Use toBeEmptyDOMElement instead of checking inner html.",
|
|
31
|
-
fix: fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean
|
|
32
|
-
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])]
|
|
29
|
+
fix: node.parent.parent.parent.arguments[0] && (fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean
|
|
30
|
+
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])])
|
|
33
31
|
});
|
|
34
32
|
},
|
|
35
33
|
[`BinaryExpression[left.property.name='firstChild'][right.value=null][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
|
|
36
34
|
context.report({
|
|
37
35
|
node,
|
|
38
36
|
message: "Use toBeEmptyDOMElement instead of checking inner html.",
|
|
39
|
-
fix: fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean
|
|
40
|
-
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])]
|
|
37
|
+
fix: node.parent.parent.parent.arguments[0] && (fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean
|
|
38
|
+
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])])
|
|
41
39
|
});
|
|
42
40
|
},
|
|
43
41
|
[`MemberExpression[property.name = 'innerHTML'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
7
4
|
exports.meta = exports.create = void 0;
|
|
8
5
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
7
|
/**
|
|
10
8
|
* @fileoverview prefer toBeDisabled or toBeEnabled over attribute checks
|
|
11
9
|
* @author Ben Monro
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
7
4
|
exports.meta = exports.create = void 0;
|
|
8
5
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
7
|
/**
|
|
10
8
|
* @fileoverview prefer toBePressed or not.toBePressed over attribute checks
|
|
11
9
|
*/
|
|
@@ -23,6 +21,6 @@ const meta = exports.meta = {
|
|
|
23
21
|
const create = exports.create = (0, _createBannedAttributeRule.default)({
|
|
24
22
|
preferred: "toBePressed",
|
|
25
23
|
negatedPreferred: "not.toBePressed",
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
mixedPreferred: "toBePartiallyPressed",
|
|
25
|
+
attributes: ["aria-pressed"]
|
|
28
26
|
});
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
7
4
|
exports.meta = exports.create = void 0;
|
|
8
5
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
7
|
/**
|
|
10
8
|
* @fileoverview prefer toBeDisabled or toBeEnabled over attribute checks
|
|
11
9
|
* @author Ben Monro
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
exports.meta = exports.create = void 0;
|
|
7
5
|
var _assignmentAst = require("../assignment-ast");
|
|
8
6
|
var _context = require("../context");
|
|
@@ -55,6 +53,23 @@ const create = context => {
|
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
55
|
},
|
|
56
|
+
// expect(element['aria-valuenow']).toBe('foo') / toEqual / toStrictEqual
|
|
57
|
+
// expect(<query>['aria-valuenow']).toBe('foo') / toEqual / toStrictEqual
|
|
58
|
+
// expect((await <query>)['aria-valuenow']).toBe('foo') / toEqual / toStrictEqual
|
|
59
|
+
[`CallExpression[callee.property.name=/to(Be|(Strict)?Equal)$/][callee.object.arguments.0.property.value='aria-valuenow'][callee.object.callee.name=expect]`](node) {
|
|
60
|
+
const valueProp = node.callee.object.arguments[0].property;
|
|
61
|
+
const matcher = node.callee.property;
|
|
62
|
+
const queryNode = node.callee.object.arguments[0].object;
|
|
63
|
+
if (isValidQueryNode(queryNode)) {
|
|
64
|
+
context.report({
|
|
65
|
+
messageId,
|
|
66
|
+
node,
|
|
67
|
+
fix(fixer) {
|
|
68
|
+
return [fixer.remove((0, _context.getSourceCode)(context).getTokenBefore(valueProp)), fixer.remove((0, _context.getSourceCode)(context).getTokenAfter(valueProp)), fixer.remove(valueProp), fixer.replaceText(matcher, "toHaveValue")];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
},
|
|
58
73
|
// expect(element.value).not.toBe('foo') / toEqual / toStrictEqual
|
|
59
74
|
// expect(<query>.value).not.toBe('foo') / toEqual / toStrictEqual
|
|
60
75
|
// expect((await <query>).value).not.toBe('foo') / toEqual / toStrictEqual
|
|
@@ -72,8 +87,26 @@ const create = context => {
|
|
|
72
87
|
});
|
|
73
88
|
}
|
|
74
89
|
},
|
|
90
|
+
// expect(element['aria-valuenow']).not.toBe('foo') / toEqual / toStrictEqual
|
|
91
|
+
// expect(<query>['aria-valuenow']).not.toBe('foo') / toEqual / toStrictEqual
|
|
92
|
+
// expect((await <query>)['aria-valuenow']).not.toBe('foo') / toEqual / toStrictEqual
|
|
93
|
+
[`CallExpression[callee.property.name=/to(Be|(Strict)?Equal)$/][callee.object.object.callee.name=expect][callee.object.property.name=not][callee.object.object.arguments.0.property.value='aria-valuenow']`](node) {
|
|
94
|
+
const queryNode = node.callee.object.object.arguments[0].object;
|
|
95
|
+
const valueProp = node.callee.object.object.arguments[0].property;
|
|
96
|
+
const matcher = node.callee.property;
|
|
97
|
+
if (isValidQueryNode(queryNode)) {
|
|
98
|
+
context.report({
|
|
99
|
+
messageId,
|
|
100
|
+
node,
|
|
101
|
+
fix(fixer) {
|
|
102
|
+
return [fixer.remove((0, _context.getSourceCode)(context).getTokenBefore(valueProp)), fixer.remove((0, _context.getSourceCode)(context).getTokenAfter(valueProp)), fixer.remove(valueProp), fixer.replaceText(matcher, "toHaveValue")];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
},
|
|
75
107
|
//expect(element).toHaveAttribute('value', 'foo') / Property
|
|
76
|
-
|
|
108
|
+
//expect(element).toHaveAttribute('aria-valuenow', 'foo') / Property
|
|
109
|
+
[`CallExpression[callee.property.name=/toHave(Attribute|Property)/][arguments.0.value=/^(value|aria-valuenow)$/][arguments.1][callee.object.callee.name=expect], CallExpression[callee.property.name=/toHave(Attribute|Property)/][arguments.0.value=/(value|aria-valuenow)$/][arguments.1][callee.object.object.callee.name=expect][callee.object.property.name=not]`](node) {
|
|
77
110
|
const matcher = node.callee.property;
|
|
78
111
|
const [prop, value] = node.arguments;
|
|
79
112
|
context.report({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-dom",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.1",
|
|
4
4
|
"description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -31,73 +31,31 @@
|
|
|
31
31
|
"index.d.ts"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "
|
|
34
|
+
"build": "babel src --out-dir dist --delete-dir-on-start --copy-files --no-copy-ignored",
|
|
35
35
|
"regenerate-docs": "npm run build && eslint-doc-generator",
|
|
36
36
|
"lint": "kcd-scripts lint",
|
|
37
|
-
"setup": "npm install
|
|
38
|
-
"test": "
|
|
37
|
+
"setup": "npm install",
|
|
38
|
+
"test": "jest",
|
|
39
39
|
"test:coverage": "npm test -- --coverage",
|
|
40
|
-
"test:update": "npm test:coverage -- --updateSnapshot"
|
|
41
|
-
"validate": "kcd-scripts validate"
|
|
40
|
+
"test:update": "npm test:coverage -- --updateSnapshot"
|
|
42
41
|
},
|
|
43
|
-
"eslintConfig": {
|
|
44
|
-
"extends": "./node_modules/kcd-scripts/eslint.js",
|
|
45
|
-
"rules": {
|
|
46
|
-
"consistent-return": "off",
|
|
47
|
-
"max-lines-per-function": "off",
|
|
48
|
-
"testing-library/no-dom-import": "off"
|
|
49
|
-
},
|
|
50
|
-
"overrides": [
|
|
51
|
-
{
|
|
52
|
-
"files": [
|
|
53
|
-
"**/*.ts"
|
|
54
|
-
],
|
|
55
|
-
"rules": {
|
|
56
|
-
"@typescript-eslint/await-thenable": "off",
|
|
57
|
-
"@typescript-eslint/dot-notation": "off",
|
|
58
|
-
"@typescript-eslint/no-base-to-string": "off",
|
|
59
|
-
"@typescript-eslint/no-floating-promises": "off",
|
|
60
|
-
"@typescript-eslint/no-implied-eval": "off",
|
|
61
|
-
"@typescript-eslint/no-misused-promises": "off",
|
|
62
|
-
"@typescript-eslint/no-throw-literal": "off",
|
|
63
|
-
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
|
|
64
|
-
"@typescript-eslint/no-unnecessary-condition": "off",
|
|
65
|
-
"@typescript-eslint/no-unnecessary-qualifier": "off",
|
|
66
|
-
"@typescript-eslint/no-unnecessary-type-assertion": "off",
|
|
67
|
-
"@typescript-eslint/no-unsafe-argument": "off",
|
|
68
|
-
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
69
|
-
"@typescript-eslint/no-unsafe-call": "off",
|
|
70
|
-
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
71
|
-
"@typescript-eslint/no-unsafe-return": "off",
|
|
72
|
-
"@typescript-eslint/prefer-includes": "off",
|
|
73
|
-
"@typescript-eslint/prefer-nullish-coalescing": "off",
|
|
74
|
-
"@typescript-eslint/prefer-reduce-type-parameter": "off",
|
|
75
|
-
"@typescript-eslint/prefer-string-starts-ends-with": "off",
|
|
76
|
-
"@typescript-eslint/restrict-plus-operands": "off",
|
|
77
|
-
"@typescript-eslint/return-await": "off",
|
|
78
|
-
"@typescript-eslint/switch-exhaustiveness-check": "off",
|
|
79
|
-
"@typescript-eslint/unbound-method": "off"
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
]
|
|
83
|
-
},
|
|
84
|
-
"eslintIgnore": [
|
|
85
|
-
"node_modules",
|
|
86
|
-
"coverage",
|
|
87
|
-
"dist",
|
|
88
|
-
"eslint-remote-tester-results"
|
|
89
|
-
],
|
|
90
42
|
"dependencies": {
|
|
91
43
|
"@babel/runtime": "^7.16.3",
|
|
92
44
|
"requireindex": "^1.2.0"
|
|
93
45
|
},
|
|
94
46
|
"devDependencies": {
|
|
47
|
+
"@babel/cli": "^7.29.7",
|
|
48
|
+
"@babel/preset-env": "^7.29.7",
|
|
95
49
|
"@testing-library/dom": "^10.4.1",
|
|
96
50
|
"@typescript-eslint/parser": "^5.9.1",
|
|
97
51
|
"eslint": "^8.7.0",
|
|
98
52
|
"eslint-doc-generator": "^3.0.0",
|
|
53
|
+
"eslint-plugin-jest": "^26.9.0",
|
|
99
54
|
"eslint-remote-tester": "^3.0.0",
|
|
100
55
|
"eslint-remote-tester-repositories": "^1.0.1",
|
|
56
|
+
"jest": "^28.1.3",
|
|
57
|
+
"jest-serializer-path": "^0.1.15",
|
|
58
|
+
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
101
59
|
"kcd-scripts": "^12.0.0",
|
|
102
60
|
"prettier": "^2.0.0",
|
|
103
61
|
"semver": "^7.6.0",
|