Skip to content

Commit e7b108d

Browse files
committed
fix: Fix false positive for expect-expect when using test.step
Fixes #149
1 parent c4c5733 commit e7b108d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/rules/expect-expect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020

2121
return {
2222
CallExpression(node) {
23-
if (isTest(node)) {
23+
if (isTest(node, ['fixme', 'only', 'skip'])) {
2424
unchecked.push(node);
2525
} else if (isExpectCall(node)) {
2626
checkExpressions(context.getAncestors());

src/utils/ast.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ export function findParent<T extends ESTree.Node['type']>(
9494
: findParent(node.parent, type);
9595
}
9696

97-
export function isTest(node: ESTree.CallExpression) {
97+
export function isTest(node: ESTree.CallExpression, modifiers?: string[]) {
9898
return (
9999
isTestIdentifier(node.callee) &&
100100
!isDescribeCall(node) &&
101+
(node.callee.type !== 'MemberExpression' ||
102+
!modifiers ||
103+
modifiers?.includes(getStringValue(node.callee.property))) &&
101104
node.arguments.length === 2 &&
102105
['ArrowFunctionExpression', 'FunctionExpression'].includes(
103106
node.arguments[1].type

test/spec/expect-expect.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dedent = require('dedent');
12
import rule from '../../src/rules/expect-expect';
23
import { runRuleTester } from '../utils/rule-tester';
34

@@ -17,5 +18,23 @@ runRuleTester('expect-expect', rule, {
1718
'["bar"]();',
1819
'testing("will test something eventually", () => {})',
1920
'test("should pass", () => expect(true).toBeDefined())',
21+
{
22+
code: dedent`
23+
test('steps', async ({ page }) => {
24+
await test.step('first tab', async () => {
25+
await expect(page.getByText('Hello')).toBeVisible();
26+
});
27+
});
28+
`,
29+
},
30+
{
31+
code: dedent`
32+
test.only('steps', async ({ page }) => {
33+
await test.step('first tab', async () => {
34+
await expect(page.getByText('Hello')).toBeVisible();
35+
});
36+
});
37+
`,
38+
},
2039
],
2140
});

0 commit comments

Comments
 (0)