From 2d0ef11137dc556f8b1e08a510d70c0dbea8a083 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 30 May 2022 08:26:49 +1200 Subject: [PATCH] fix(expect-expect): include numbers when matching assert function names with wildcards (#1134) --- src/rules/__tests__/expect-expect.test.ts | 8 ++++++++ src/rules/expect-expect.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rules/__tests__/expect-expect.test.ts b/src/rules/__tests__/expect-expect.test.ts index c2f02ed84..137ab45a6 100644 --- a/src/rules/__tests__/expect-expect.test.ts +++ b/src/rules/__tests__/expect-expect.test.ts @@ -187,6 +187,14 @@ ruleTester.run('expect-expect', rule, { ruleTester.run('wildcards', rule, { valid: [ + { + code: "test('should pass *', () => expect404ToBeLoaded());", + options: [{ assertFunctionNames: ['expect*'] }], + }, + { + code: "test('should pass *', () => expect.toHaveStatus404());", + options: [{ assertFunctionNames: ['expect.**'] }], + }, { code: "test('should pass', () => tester.foo().expect(123));", options: [{ assertFunctionNames: ['tester.*.expect'] }], diff --git a/src/rules/expect-expect.ts b/src/rules/expect-expect.ts index c7c61ccff..08a836e4a 100644 --- a/src/rules/expect-expect.ts +++ b/src/rules/expect-expect.ts @@ -28,9 +28,9 @@ function matchesAssertFunctionName( `^${p .split('.') .map(x => { - if (x === '**') return '[a-z\\.]*'; + if (x === '**') return '[a-z\\d\\.]*'; - return x.replace(/\*/gu, '[a-z]*'); + return x.replace(/\*/gu, '[a-z\\d]*'); }) .join('\\.')}(\\.|$)`, 'ui',