From fca395a2b1489152ebfff7d663bba7e2dfca4515 Mon Sep 17 00:00:00 2001 From: Guillaume Gautreau Date: Thu, 19 Dec 2024 16:39:05 +0100 Subject: [PATCH] fix: detect expectations in chains with underscores --- src/rules/expect-expect.ts | 2 +- tests/expect-expect.test.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/rules/expect-expect.ts b/src/rules/expect-expect.ts index 3c1873b..5f6b556 100644 --- a/src/rules/expect-expect.ts +++ b/src/rules/expect-expect.ts @@ -22,7 +22,7 @@ function matchesAssertFunctionName( .split('.') .map((x) => { if (x === '**') - return '[a-z\\d\\.]*' + return '[_a-z\\d\\.]*' return x.replace(/\*/gu, '[a-z\\d]*') }) diff --git a/tests/expect-expect.test.ts b/tests/expect-expect.test.ts index 39a7e1d..6d14b2f 100644 --- a/tests/expect-expect.test.ts +++ b/tests/expect-expect.test.ts @@ -1,6 +1,7 @@ -import { AST_NODE_TYPES } from '@typescript-eslint/utils' -import rule, { RULE_NAME } from '../src/rules/expect-expect' -import { ruleTester } from './ruleTester' +import { AST_NODE_TYPES } from '@typescript-eslint/utils'; + +import rule, { RULE_NAME } from '../src/rules/expect-expect'; +import { ruleTester } from './ruleTester'; ruleTester.run(RULE_NAME, rule, { valid: [ @@ -42,7 +43,15 @@ it('example', async () => { const result = Promise.reject('error'); await expect(result.then((it) => it.toUpperCase())).rejects.toThrow(); -});` +});`, + { + code: `it("should pass", () => { anyChain.of.calls.expect(true) })`, + options: [{ assertFunctionNames: ['**.expect'] }] + }, + { + code: `it("should pass", () => { any_chain.of.calls.expect(true) })`, + options: [{ assertFunctionNames: ['**.expect'] }] + } ], invalid: [ {