From 5e95a5a3c3a358d0135aeeb33c8a4b0072ad0991 Mon Sep 17 00:00:00 2001 From: TimZM Date: Thu, 22 Aug 2024 11:34:15 +0200 Subject: [PATCH] fix(expect-single-argument): Allow no arguments when using nothing (#373) Closes #176 --- docs/rules/expect-single-argument.md | 3 ++- lib/rules/expect-single-argument.js | 2 +- test/rules/expect-single-argument.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/rules/expect-single-argument.md b/docs/rules/expect-single-argument.md index 56c1f14..b6e60fd 100644 --- a/docs/rules/expect-single-argument.md +++ b/docs/rules/expect-single-argument.md @@ -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(); @@ -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(); ``` diff --git a/lib/rules/expect-single-argument.js b/lib/rules/expect-single-argument.js index a54cf17..778ef31 100644 --- a/lib/rules/expect-single-argument.js +++ b/lib/rules/expect-single-argument.js @@ -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 diff --git a/test/rules/expect-single-argument.js b/test/rules/expect-single-argument.js index 890bb1d..fbe0a1e 100644 --- a/test/rules/expect-single-argument.js +++ b/test/rules/expect-single-argument.js @@ -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: [