diff --git a/src/rules/expect-expect.ts b/src/rules/expect-expect.ts index 2a0c664..3b6190c 100644 --- a/src/rules/expect-expect.ts +++ b/src/rules/expect-expect.ts @@ -1,6 +1,6 @@ import { Rule } from 'eslint'; import * as ESTree from 'estree'; -import { isExpectCall, isIdentifier, isTest } from '../utils/ast'; +import { dig, isExpectCall, isTest } from '../utils/ast'; import { getAdditionalAssertFunctionNames } from '../utils/misc'; function isAssertionCall( @@ -9,9 +9,7 @@ function isAssertionCall( ) { return ( isExpectCall(node) || - additionalAssertFunctionNames.find((name) => - isIdentifier(node.callee, name), - ) + additionalAssertFunctionNames.find((name) => dig(node.callee, name)) ); } @@ -38,7 +36,7 @@ export default { if (isTest(node, ['fixme', 'only', 'skip'])) { unchecked.push(node); } else if (isAssertionCall(node, additionalAssertFunctionNames)) { - checkExpressions(context.getAncestors()); + checkExpressions(context.sourceCode.getAncestors(node)); } }, 'Program:exit'() { diff --git a/src/utils/ast.ts b/src/utils/ast.ts index 828ebc1..516b2ef 100644 --- a/src/utils/ast.ts +++ b/src/utils/ast.ts @@ -158,7 +158,7 @@ export function getMatchers( * Digs through a series of MemberExpressions and CallExpressions to find an * Identifier with the given name. */ -function dig(node: ESTree.Node, identifier: string | RegExp): boolean { +export function dig(node: ESTree.Node, identifier: string | RegExp): boolean { return node.type === 'MemberExpression' ? dig(node.property, identifier) : node.type === 'CallExpression' diff --git a/test/spec/expect-expect.spec.ts b/test/spec/expect-expect.spec.ts index f71444e..da88de8 100644 --- a/test/spec/expect-expect.spec.ts +++ b/test/spec/expect-expect.spec.ts @@ -93,7 +93,20 @@ runRuleTester('expect-expect', rule, { await assertCustomCondition(page) }) `, - name: 'Global settings only', + name: 'Custom assert function', + settings: { + playwright: { + additionalAssertFunctionNames: ['assertCustomCondition'], + }, + }, + }, + { + code: dedent` + test('should fail', async ({ myPage, page }) => { + await myPage.assertCustomCondition(page) + }) + `, + name: 'Custom assert class method', settings: { playwright: { additionalAssertFunctionNames: ['assertCustomCondition'],