Skip to content

Commit 47249ce

Browse files
authored
fix: Ignore expect without assertion in missing-playwright-await (#201)
1 parent 5bc943f commit 47249ce

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/rules/missing-playwright-await.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ function getCallType(
7777
if (!expectType) return;
7878

7979
const [lastMatcher] = getMatchers(node).slice(-1);
80-
const grandparent = lastMatcher.parent.parent;
80+
const grandparent = lastMatcher?.parent?.parent;
8181

8282
// If the grandparent is not a CallExpression, then it's an incomplete
8383
// expect statement, and we don't need to check it.
84-
if (grandparent.type !== 'CallExpression') return;
84+
if (grandparent?.type !== 'CallExpression') return;
8585

8686
const matcherName = getStringValue(lastMatcher);
8787

@@ -152,6 +152,7 @@ export default {
152152
return {
153153
CallExpression(node) {
154154
const result = getCallType(node, awaitableMatchers);
155+
console.log(result);
155156
const isValid = result ? checkValidity(result.node) : false;
156157

157158
if (result && !isValid) {

test/spec/missing-playwright-await.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ runRuleTester('missing-playwright-await', rule, {
216216
},
217217
],
218218
valid: [
219+
// Basic
219220
{ code: test('await expect(page).toBeEditable') },
220221
{ code: test('await expect(page).toEqualTitle("text")') },
221222
{ code: test('await expect(page).not.toHaveText("text")') },
223+
// Invalid expect calls are ignored
224+
{ code: 'expect.soft(page.locator("foo"))' },
222225
// Doesn't require an await when returning
223226
{ code: test('return expect(page).toHaveText("text")') },
224227
{

0 commit comments

Comments
 (0)