Skip to content

Commit

Permalink
fix(expect-single-argument): Allow no arguments when using nothing (#373
Browse files Browse the repository at this point in the history
)

Closes #176
  • Loading branch information
TimZM authored Aug 22, 2024
1 parent f9e0798 commit 5e95a5a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/rules/expect-single-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Ensure `expect` is called with a single argument.

## Rule details

This rule triggers a warning if `expect` is called with more than one argument or without arguments.
This rule triggers a warning if `expect` is called with more than one argument or without arguments when not followed by a `nothing()`.

```js
expect();
Expand All @@ -27,4 +27,5 @@ The following patterns are not warnings:
expect("something").toEqual("something");
expect([1, 2, 3]).toEqual([1, 2, 3]);
expect(true).toBeDefined();
expect().nothing();
```
2 changes: 1 addition & 1 deletion lib/rules/expect-single-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function create (context) {
message: 'Expect must have a single argument. More than one argument were provided.',
node
})
} else if (node.arguments.length === 0) {
} else if (node.arguments.length === 0 && node.parent.property.name !== 'nothing') {
context.report({
message: 'Expect must have a single argument. No arguments were provided.',
node
Expand Down
3 changes: 2 additions & 1 deletion test/rules/expect-single-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ eslintTester.run('expect-single-argument', rule, {
'expect("something").toEqual("else");',
'expect(true).toBeDefined();',
'expect([1, 2, 3]).toEqual([1, 2, 3]);',
'expect(undefined).not.toBeDefined();'
'expect(undefined).not.toBeDefined();',
'expect().nothing();'
],

invalid: [
Expand Down

0 comments on commit 5e95a5a

Please sign in to comment.