Skip to content

Commit

Permalink
fix(prefer-web-first-assertions): Fix error with nested call expressions
Browse files Browse the repository at this point in the history
Fixes #276
  • Loading branch information
mskelton committed Mar 20, 2024
1 parent ae78045 commit bf821f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/rules/prefer-web-first-assertions.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dedent from 'dedent'
import rule from '../../src/rules/prefer-web-first-assertions'
import { runRuleTester, test } from '../utils/rule-tester'

Expand Down Expand Up @@ -708,6 +709,17 @@ runRuleTester('prefer-web-first-assertions', rule, {
{ code: test('let visible = await foo.isVisible()') },
{ code: test('const value = await bar["inputValue"]()') },
{ code: test('const isEditable = await baz[`isEditable`]()') },
{
code: dedent`
import { expect } from '@playwright/test';
test('my test', async ({ page }) => {
await expect
.poll(() => foo, { message })
.toEqual(expect.objectContaining({ bar: expect.anything() }));
});
`,
},
// Global aliases
{
code: test('await assert(page.locator(".tweet")).toBeVisible()'),
Expand Down
4 changes: 2 additions & 2 deletions src/rules/prefer-web-first-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const supportedMatchers = new Set([
* If the expect call argument is a variable reference, finds the variable
* initializer.
*/
function dereference(context: Rule.RuleContext, node: ESTree.Node) {
if (node.type !== 'Identifier') {
function dereference(context: Rule.RuleContext, node: ESTree.Node | undefined) {
if (node?.type !== 'Identifier') {
return node
}

Expand Down

0 comments on commit bf821f5

Please sign in to comment.