Skip to content

Commit fc405f2

Browse files
authored
Merge branch 'master' into fix-banner-attribute-rule
2 parents 4bb0385 + 40353d3 commit fc405f2

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

.all-contributorsrc

+11
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@
154154
"code",
155155
"test"
156156
]
157+
},
158+
{
159+
"login": "G-Rath",
160+
"name": "Gareth Jones",
161+
"avatar_url": "https://avatars.githubusercontent.com/u/3151613?v=4",
162+
"profile": "https://github.com/G-Rath",
163+
"contributions": [
164+
"test",
165+
"code",
166+
"bug"
167+
]
157168
}
158169
]
159170
}

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[![MIT License][license-badge]][license]
1515

1616
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
17-
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)
17+
[![All Contributors](https://img.shields.io/badge/all_contributors-15-orange.svg?style=flat-square)](#contributors-)
1818
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1919
[![PRs Welcome][prs-badge]][prs]
2020
[![Code of Conduct][coc-badge]][coc]
@@ -161,6 +161,9 @@ Thanks goes to these people ([emoji key][emojis]):
161161
<td align="center"><a href="http://juzerzarif.com"><img src="https://avatars3.githubusercontent.com/u/22772637?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juzer Zarif</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=juzerzarif" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=juzerzarif" title="Tests">⚠️</a> <a href="https://github.com/testing-library/eslint-plugin-jest-dom/issues?q=author%3Ajuzerzarif" title="Bug reports">🐛</a></td>
162162
<td align="center"><a href="http://everlong.org/"><img src="https://avatars.githubusercontent.com/u/454175?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Julien Wajsberg</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=julienw" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-jest-dom/commits?author=julienw" title="Tests">⚠️</a></td>
163163
</tr>
164+
<tr>
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+
</tr>
164167
</table>
165168

166169
<!-- markdownlint-restore -->

src/__tests__/lib/rules/prefer-in-document.js

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const valid = [
3636
foo = somethingElse;
3737
expect(foo).toHaveLength(1);`,
3838
]),
39+
`expect().not.toBeNull()`,
40+
`expect(myFunction()).toBe();`,
41+
`expect(myFunction()).toHaveLength();`,
3942
`let foo;
4043
foo = "bar";
4144
expect(foo).toHaveLength(1);`,

src/rules/prefer-in-document.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ function isAntonymMatcher(matcherNode, matcherArguments) {
3232
}
3333

3434
function usesToBeOrToEqualWithNull(matcherNode, matcherArguments) {
35-
return (matcherNode.name === "toBe" || matcherNode.name === "toEqual") &&
36-
matcherArguments[0].value === null;
35+
return (
36+
(matcherNode.name === "toBe" || matcherNode.name === "toEqual") &&
37+
matcherArguments[0].value === null
38+
);
3739
}
3840

3941
function usesToHaveLengthZero(matcherNode, matcherArguments) {
@@ -71,7 +73,7 @@ export const create = (context) => {
7173
if (!queryNode || (!queryNode.name && !queryNode.property)) return;
7274

7375
// toHaveLength() is only invalid with 0 or 1
74-
if (matcherNode.name === "toHaveLength") {
76+
if (matcherNode.name === "toHaveLength" && matcherArguments.length) {
7577
const lengthValue = getLengthValue(matcherArguments);
7678
// isNotToHaveLengthZero represents .not.toHaveLength(0) which is a valid use of toHaveLength
7779
const isNotToHaveLengthZero =
@@ -89,7 +91,10 @@ export const create = (context) => {
8991

9092
// toBe() or toEqual() are only invalid with null
9193
if (matcherNode.name === "toBe" || matcherNode.name === "toEqual") {
92-
if (!usesToBeOrToEqualWithNull(matcherNode, matcherArguments)) {
94+
if (
95+
!matcherArguments.length ||
96+
!usesToBeOrToEqualWithNull(matcherNode, matcherArguments)
97+
) {
9398
return;
9499
}
95100
}
@@ -146,6 +151,10 @@ export const create = (context) => {
146151
[`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}]`](
147152
node
148153
) {
154+
if (!node.callee.object.object.arguments.length) {
155+
return;
156+
}
157+
149158
const arg = node.callee.object.object.arguments[0];
150159
const queryNode =
151160
arg.type === "AwaitExpression" ? arg.argument.callee : arg.callee;

0 commit comments

Comments
 (0)