Skip to content

Commit e11113e

Browse files
authoredOct 22, 2023
fix: Check class methods in expect-expect (#172)
1 parent ecc406a commit e11113e

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
 

‎src/rules/expect-expect.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Rule } from 'eslint';
22
import * as ESTree from 'estree';
3-
import { isExpectCall, isIdentifier, isTest } from '../utils/ast';
3+
import { dig, isExpectCall, isTest } from '../utils/ast';
44
import { getAdditionalAssertFunctionNames } from '../utils/misc';
55

66
function isAssertionCall(
@@ -9,9 +9,7 @@ function isAssertionCall(
99
) {
1010
return (
1111
isExpectCall(node) ||
12-
additionalAssertFunctionNames.find((name) =>
13-
isIdentifier(node.callee, name),
14-
)
12+
additionalAssertFunctionNames.find((name) => dig(node.callee, name))
1513
);
1614
}
1715

@@ -38,7 +36,7 @@ export default {
3836
if (isTest(node, ['fixme', 'only', 'skip'])) {
3937
unchecked.push(node);
4038
} else if (isAssertionCall(node, additionalAssertFunctionNames)) {
41-
checkExpressions(context.getAncestors());
39+
checkExpressions(context.sourceCode.getAncestors(node));
4240
}
4341
},
4442
'Program:exit'() {

‎src/utils/ast.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function getMatchers(
158158
* Digs through a series of MemberExpressions and CallExpressions to find an
159159
* Identifier with the given name.
160160
*/
161-
function dig(node: ESTree.Node, identifier: string | RegExp): boolean {
161+
export function dig(node: ESTree.Node, identifier: string | RegExp): boolean {
162162
return node.type === 'MemberExpression'
163163
? dig(node.property, identifier)
164164
: node.type === 'CallExpression'

‎test/spec/expect-expect.spec.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,20 @@ runRuleTester('expect-expect', rule, {
9393
await assertCustomCondition(page)
9494
})
9595
`,
96-
name: 'Global settings only',
96+
name: 'Custom assert function',
97+
settings: {
98+
playwright: {
99+
additionalAssertFunctionNames: ['assertCustomCondition'],
100+
},
101+
},
102+
},
103+
{
104+
code: dedent`
105+
test('should fail', async ({ myPage, page }) => {
106+
await myPage.assertCustomCondition(page)
107+
})
108+
`,
109+
name: 'Custom assert class method',
97110
settings: {
98111
playwright: {
99112
additionalAssertFunctionNames: ['assertCustomCondition'],

0 commit comments

Comments
 (0)
Please sign in to comment.