cypress-io / eslint-plugin-cypress

An ESLint plugin for projects that use Cypress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When using a const imported from another file we get "TypeError: Cannot read properties of undefined"

JoneSabino opened this issue · comments

Hello, I'm facing an issue when using the cypress/no-unnecessary-waiting rule in my project. I have encountered the following error:

TypeError: Cannot read properties of undefined (reading 'undefined')
Occurred while linting /path/to/file.ts:200
Rule: "cypress/no-unnecessary-waiting"
    at isIdentifierNumberConstArgument (/path/to/node_modules/eslint-plugin-cypress/lib/rules/no-unnecessary-waiting.js:72:39)
    at CallExpression (/path/to/node_modules/eslint-plugin-cypress/lib/rules/no-unnecessary-waiting.js:22:15)
    at ruleErrorHandler (/path/to/node_modules/eslint/lib/linter/linter.js:1114:28)
    at /path/to/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/path/to/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/path/to/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/path/to/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/path/to/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/path/to/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23) 

Here is the relevant code snippet from my project:

import { TWO_SECONDS } from src/constants

registerPromoVoidItem() {
  // eslint-disable-next-line cypress/no-unnecessary-waiting
  cy.wait(TWO_SECONDS);
}

As you can see, I have already added // eslint-disable-next-line cypress/no-unnecessary-waiting to the code, but the error still occurs.

I have tried to update eslint-plugin-cypress to the latest version, however, the issue persists.

Steps to reproduce:

  1. Create any const in one file(A);
  2. import the const from file A on file B;
  3. On file B call cy.wait(YOUR_CONST);

Could you please help me understand if there's a bug in the plugin, or if I'm doing something wrong in my code? Any help would be appreciated. Thank you!

Plugin version: 2.13.2
Eslint Version: 8.15.0
Typescript version: 4.9.5

@JoneSabino Please provide a reproducible example of the issue you're encountering. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

This will help us make sure we are testing the exact same thing that you are. Thanks!

Hey, @JoneSabino this should be fixed in 2.13.3 by #109, can you re-check on that version?

Hey, @JoneSabino this should be fixed in 2.13.3 by #109, can you re-check on that version?

Awesome! Gonna test in that version and see what happens.

Thanks!

Since there hasn't been any followup, I'll close this issue for now: please comment if there is still a problem after you've upgraded.