Skip to content

Commit

Permalink
fix: Ignore expect without assertion in missing-playwright-await (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton authored Jan 18, 2024
1 parent 5bc943f commit 47249ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/rules/missing-playwright-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ function getCallType(
if (!expectType) return;

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

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

const matcherName = getStringValue(lastMatcher);

Expand Down Expand Up @@ -152,6 +152,7 @@ export default {
return {
CallExpression(node) {
const result = getCallType(node, awaitableMatchers);
console.log(result);
const isValid = result ? checkValidity(result.node) : false;

if (result && !isValid) {
Expand Down
3 changes: 3 additions & 0 deletions test/spec/missing-playwright-await.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,12 @@ runRuleTester('missing-playwright-await', rule, {
},
],
valid: [
// Basic
{ code: test('await expect(page).toBeEditable') },
{ code: test('await expect(page).toEqualTitle("text")') },
{ code: test('await expect(page).not.toHaveText("text")') },
// Invalid expect calls are ignored
{ code: 'expect.soft(page.locator("foo"))' },
// Doesn't require an await when returning
{ code: test('return expect(page).toHaveText("text")') },
{
Expand Down

0 comments on commit 47249ce

Please sign in to comment.