playwright-community / eslint-plugin-playwright

ESLint plugin for Playwright
https://www.npmjs.com/package/eslint-plugin-playwright
MIT License
272 stars 37 forks source link

[Bug] TypeError: Cannot read properties of undefined (reading 'parent') while linting expect.soft(await pageInstance.asyncFunction()) #200

Closed python012 closed 9 months ago

python012 commented 9 months ago

When I tried to run eslint, I got error TypeError: Cannot read properties of undefined (reading 'parent') while linting the code of expect.soft(await loginPage.clickOnLoginBtn())

my package.json

"devDependencies": {
    "@playwright/test": "^1.36.1",
    "@typescript-eslint/eslint-plugin": "^5.62.0",
    "@typescript-eslint/parser": "^5.62.0",
    "@wdio/allure-reporter": "^7.19.0",
    "allure-commandline": "^2.17.2",
    "allure-playwright": "^2.0.0-beta.15",
    "chai": "^4.3.6",
    "eslint": "^8.56.0",
    "eslint-config-google": "^0.14.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-playwright": "^0.21.0",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-react": "^7.30.0",
    "mocha": "^10.0.0",
    "prettier": "2.6.2",
    "xunit-viewer": "^7.1.5"
  },

my .eslintrc.json

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": ["plugin:@typescript-eslint/recommended", "plugin:playwright/recommended", "google", "prettier"],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2021,
    "sourceType": "module"
  },
  "plugins": ["@typescript-eslint", "prettier", "playwright"],
  "rules": {
    "prettier/prettier": "warn",
    "max-len": "off",
    "valid-jsdoc": "warn",
    "require-jsdoc": "off", // require-jsdoc was deprecated in ESLint v5.10.0
    "linebreak-style": "off",
    "no-unused-vars": "warn",
    "spaced-comment": ["error", "always", { "markers": ["/"] }],
    "array-element-newline": ["off", "always"]
  }
}
D:\dev3\TestAutomation>npm run lint

> testautomation@1.0.0 lint
> eslint . --ext js,jsx,ts,tsx

Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Cannot read properties of undefined (reading 'parent')
Occurred while linting D:\dev3\TestAutomation\testcases\TestAcs.spec.ts:185
Rule: "playwright/missing-playwright-await"
    at getCallType (D:\dev3\TestAutomation\node_modules\eslint-plugin-playwright\dist\index.js:312:35)
    at CallExpression (D:\dev3\TestAutomation\node_modules\eslint-plugin-playwright\dist\index.js:357:24)
    at ruleErrorHandler (D:\dev3\TestAutomation\node_modules\eslint\lib\linter\linter.js:1076:28

The code of TestAcs.spec.ts:185 is expect.soft(await loginPage.clickOnLoginBtn());

the function is defined as following, and yes this line of code is not good..

  async clickOnLoginBtn() {
    await this.clickOnLoginBtn.click();
  }

after I added "playwright/missing-playwright-await": "off" to rules, and ran eslint, this error was gone

mskelton commented 9 months ago

@python012 While I'll be investigating this error, as a note expect.soft(await loginPage.clickOnLoginBtn()) is not a valid expect since you don't have an assertion.

github-actions[bot] commented 9 months ago

:tada: This issue has been resolved in version 0.22.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: