eslint-plugin-jest-dom 3.9.0 → 3.9.4
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 +17 -15
- package/dist/assignment-ast.js +2 -2
- package/dist/index.js +1 -1
- package/dist/rules/prefer-checked.js +1 -1
- package/dist/rules/prefer-empty.js +1 -1
- package/dist/rules/prefer-enabled-disabled.js +1 -1
- package/dist/rules/prefer-focus.js +1 -1
- package/dist/rules/prefer-in-document.js +6 -1
- package/dist/rules/prefer-required.js +1 -1
- package/dist/rules/prefer-to-have-attribute.js +4 -4
- package/dist/rules/prefer-to-have-class.js +1 -1
- package/dist/rules/prefer-to-have-style.js +1 -1
- package/dist/rules/prefer-to-have-text-content.js +1 -1
- package/dist/rules/prefer-to-have-value.js +1 -1
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
[![MIT License][license-badge]][license]
|
|
15
15
|
|
|
16
16
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
17
|
-
[](#contributors-)
|
|
18
18
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
19
19
|
[![PRs Welcome][prs-badge]][prs]
|
|
20
20
|
[![Code of Conduct][coc-badge]][coc]
|
|
@@ -46,7 +46,7 @@ should be installed as one of your project's `devDependencies`:
|
|
|
46
46
|
npm install --save-dev eslint-plugin-jest-dom
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
This library has a required `peerDependencies` listing for [`
|
|
49
|
+
This library has a required `peerDependencies` listing for [`ESLint`](https://eslint.org/).
|
|
50
50
|
|
|
51
51
|
## Usage
|
|
52
52
|
|
|
@@ -103,17 +103,17 @@ module.exports = {
|
|
|
103
103
|
|
|
104
104
|
| Name | 👍 | 🔧 | Description |
|
|
105
105
|
| ---------------------------------------------------------------------------------------------------------------------------------------------- | --- | --- | --------------------------------------------------------------------- |
|
|
106
|
-
| [prefer-checked](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
107
|
-
| [prefer-empty](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
108
|
-
| [prefer-enabled-disabled](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
109
|
-
| [prefer-focus](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
110
|
-
| [prefer-in-document](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
111
|
-
| [prefer-required](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
112
|
-
| [prefer-to-have-attribute](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
113
|
-
| [prefer-to-have-class](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
114
|
-
| [prefer-to-have-style](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
115
|
-
| [prefer-to-have-text-content](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
116
|
-
| [prefer-to-have-value](https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
106
|
+
| [prefer-checked](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-checked.md) | 👍 | 🔧 | prefer toBeChecked over checking attributes |
|
|
107
|
+
| [prefer-empty](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-empty.md) | 👍 | 🔧 | Prefer toBeEmpty over checking innerHTML |
|
|
108
|
+
| [prefer-enabled-disabled](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-enabled-disabled.md) | 👍 | 🔧 | prefer toBeDisabled or toBeEnabled over checking attributes |
|
|
109
|
+
| [prefer-focus](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-focus.md) | 👍 | 🔧 | prefer toHaveFocus over checking document.activeElement |
|
|
110
|
+
| [prefer-in-document](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-in-document.md) | 👍 | 🔧 | Prefer .toBeInTheDocument() for asserting the existence of a DOM node |
|
|
111
|
+
| [prefer-required](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-required.md) | 👍 | 🔧 | prefer toBeRequired over checking properties |
|
|
112
|
+
| [prefer-to-have-attribute](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-to-have-attribute.md) | 👍 | 🔧 | prefer toHaveAttribute over checking getAttribute/hasAttribute |
|
|
113
|
+
| [prefer-to-have-class](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-to-have-class.md) | 👍 | 🔧 | prefer toHaveClass over checking element className |
|
|
114
|
+
| [prefer-to-have-style](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-to-have-style.md) | 👍 | 🔧 | prefer toHaveStyle over checking element style |
|
|
115
|
+
| [prefer-to-have-text-content](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-to-have-text-content.md) | 👍 | 🔧 | Prefer toHaveTextContent over checking element.textContent |
|
|
116
|
+
| [prefer-to-have-value](https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/docs/rules/prefer-to-have-value.md) | 👍 | 🔧 | prefer toHaveValue over checking element.value |
|
|
117
117
|
|
|
118
118
|
<!-- __END AUTOGENERATED TABLE__ -->
|
|
119
119
|
|
|
@@ -163,6 +163,8 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
163
163
|
</tr>
|
|
164
164
|
<tr>
|
|
165
165
|
<td align="center"><a href="https://github.com/G-Rath"><img src="https://avatars.githubusercontent.com/u/3151613?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gareth Jones</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=G-Rath" title="Tests">⚠️</a> <a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=G-Rath" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-jest-dom/issues?q=author%3AG-Rath" title="Bug reports">🐛</a></td>
|
|
166
|
+
<td align="center"><a href="https://github.com/huyenltnguyen"><img src="https://avatars.githubusercontent.com/u/25715018?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Huyen Nguyen</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=huyenltnguyen" title="Documentation">📖</a></td>
|
|
167
|
+
<td align="center"><a href="https://github.com/mdotwills"><img src="https://avatars.githubusercontent.com/u/5505611?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matthew</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-jest-dom/issues?q=author%3Amdotwills" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=mdotwills" title="Code">💻</a></td>
|
|
166
168
|
</tr>
|
|
167
169
|
</table>
|
|
168
170
|
|
|
@@ -190,11 +192,11 @@ MIT
|
|
|
190
192
|
[downloads-badge]: https://img.shields.io/npm/dm/eslint-plugin-jest-dom.svg?style=flat-square
|
|
191
193
|
[npmtrends]: http://www.npmtrends.com/eslint-plugin-jest-dom
|
|
192
194
|
[license-badge]: https://img.shields.io/npm/l/eslint-plugin-jest-dom.svg?style=flat-square
|
|
193
|
-
[license]: https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
195
|
+
[license]: https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/LICENSE
|
|
194
196
|
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
|
195
197
|
[prs]: http://makeapullrequest.com
|
|
196
198
|
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
|
|
197
|
-
[coc]: https://github.com/testing-library/eslint-plugin-jest-dom/blob/
|
|
199
|
+
[coc]: https://github.com/testing-library/eslint-plugin-jest-dom/blob/main/other/CODE_OF_CONDUCT.md
|
|
198
200
|
[emojis]: https://github.com/all-contributors/all-contributors#emoji-key
|
|
199
201
|
[all-contributors]: https://github.com/all-contributors/all-contributors
|
|
200
202
|
[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
|
package/dist/assignment-ast.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getInnerNodeFrom = getInnerNodeFrom;
|
|
7
6
|
exports.getAssignmentForIdentifier = getAssignmentForIdentifier;
|
|
7
|
+
exports.getInnerNodeFrom = getInnerNodeFrom;
|
|
8
8
|
exports.getQueryNodeFrom = getQueryNodeFrom;
|
|
9
9
|
|
|
10
10
|
var _queries = require("./queries");
|
|
@@ -85,7 +85,7 @@ function getQueryNodeFrom(context, nodeWithValueProp) {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const query = queryNode.callee.name || queryNode.callee.property.name;
|
|
88
|
+
const query = queryNode.callee.name || queryNode.callee.property && queryNode.callee.property.name;
|
|
89
89
|
const queryArg = queryNode.arguments[0] && queryNode.arguments[0].value;
|
|
90
90
|
|
|
91
91
|
const isDTLQuery = _queries.queries.includes(query);
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.rules = exports.generateRecommendedConfig = exports.generateAllRulesConfig = exports.configs = void 0;
|
|
9
9
|
|
|
10
10
|
var _requireindex = _interopRequireDefault(require("requireindex"));
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.meta = exports.create = void 0;
|
|
9
9
|
|
|
10
10
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.meta = exports.create = void 0;
|
|
9
9
|
|
|
10
10
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
11
11
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.meta = exports.create = void 0;
|
|
7
7
|
|
|
8
8
|
var _queries = require("../queries");
|
|
9
9
|
|
|
@@ -180,6 +180,11 @@ const create = context => {
|
|
|
180
180
|
// expect(<query>).<matcher>
|
|
181
181
|
[`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) {
|
|
182
182
|
const arg = node.callee.object.arguments[0];
|
|
183
|
+
|
|
184
|
+
if (!arg) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
183
188
|
const queryNode = arg.type === "AwaitExpression" ? arg.argument.callee : arg.callee;
|
|
184
189
|
const matcherNode = node.callee.property;
|
|
185
190
|
const matcherArguments = node.arguments;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.meta = exports.create = void 0;
|
|
9
9
|
|
|
10
10
|
var _createBannedAttributeRule = _interopRequireDefault(require("../createBannedAttributeRule"));
|
|
11
11
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.meta = exports.create = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
|
|
@@ -43,14 +43,14 @@ const create = context => ({
|
|
|
43
43
|
|
|
44
44
|
[`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) {
|
|
45
45
|
const arg = node.parent.parent.parent.arguments;
|
|
46
|
-
const
|
|
46
|
+
const isNull = arg.length > 0 && arg[0].value === null;
|
|
47
47
|
const sourceCode = context.getSourceCode();
|
|
48
48
|
context.report({
|
|
49
49
|
node: node.parent,
|
|
50
50
|
message: `Use toHaveAttribute instead of asserting on getAttribute`,
|
|
51
51
|
fix: fixer => {
|
|
52
|
-
const lastFixer =
|
|
53
|
-
return [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, `${
|
|
52
|
+
const lastFixer = isNull ? fixer.replaceText(node.parent.parent.parent.arguments[0], sourceCode.getText(node.arguments[0])) : fixer.insertTextBefore(node.parent.parent.parent.arguments[0], `${sourceCode.getText(node.arguments[0])}, `);
|
|
53
|
+
return [fixer.removeRange([node.callee.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, `${isNull ? "not." : ""}toHaveAttribute`), lastFixer];
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-dom",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.4",
|
|
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": [
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"lint": "kcd-scripts lint",
|
|
36
36
|
"setup": "npm install && npm run validate -s",
|
|
37
37
|
"test": "kcd-scripts test",
|
|
38
|
-
"test:
|
|
39
|
-
"test:update": "npm test -- --updateSnapshot
|
|
38
|
+
"test:coverage": "npm test -- --coverage",
|
|
39
|
+
"test:update": "npm test:coverage -- --updateSnapshot",
|
|
40
40
|
"validate": "kcd-scripts validate"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@babel/runtime": "^7.
|
|
44
|
-
"@testing-library/dom": "^7.
|
|
43
|
+
"@babel/runtime": "^7.16.3",
|
|
44
|
+
"@testing-library/dom": "^7.31.2",
|
|
45
45
|
"requireindex": "^1.2.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@typescript-eslint/parser": "^4.
|
|
49
|
-
"eslint": "7.
|
|
50
|
-
"eslint-remote-tester": "^0.
|
|
51
|
-
"
|
|
52
|
-
"kcd-scripts": "
|
|
53
|
-
"typescript": "^4.
|
|
48
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
49
|
+
"eslint": "^7.31.0",
|
|
50
|
+
"eslint-remote-tester": "^2.0.1",
|
|
51
|
+
"eslint-remote-tester-repositories": "^0.0.3",
|
|
52
|
+
"kcd-scripts": "^11.2.2",
|
|
53
|
+
"typescript": "^4.5.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"eslint": ">=6.8"
|
|
@@ -68,7 +68,6 @@
|
|
|
68
68
|
"node_modules",
|
|
69
69
|
"coverage",
|
|
70
70
|
"dist",
|
|
71
|
-
".cache-eslint-remote-tester",
|
|
72
71
|
"eslint-remote-tester-results"
|
|
73
72
|
],
|
|
74
73
|
"engines": {
|