Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unnecessary-waiting: TypeError: Cannot read property 'null' of undefined #43

Closed
ggascoigne opened this issue Feb 10, 2020 · 13 comments · Fixed by #109
Closed

no-unnecessary-waiting: TypeError: Cannot read property 'null' of undefined #43

ggascoigne opened this issue Feb 10, 2020 · 13 comments · Fixed by #109
Labels

Comments

@ggascoigne
Copy link

using eslint-plugin-cypress@2.9.0

2.8.1 works fine, but 2.9.0 throws an error on

      cy.login(adapterUser).wait(5000)
TypeError: Cannot read property 'null' of undefined
Occurred while linting /Users/ggp/dev/tw-git/saas-ui/cypress/integration/systems/settings.systems.datasource.connect.request.negative.spec.js:24
    at isIdentifierNumberConstArgument (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint-plugin-cypress/lib/rules/no-unnecessary-waiting.js:76:39)
    at CallExpression (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint-plugin-cypress/lib/rules/no-unnecessary-waiting.js:27:15)
    at /Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at /Users/ggp/dev/tw-git/saas-ui/node_modules/eslint/lib/linter/linter.js:936:32
error Command failed with exit code 2.
@jennifer-shehane
Copy link
Member

I'm unable to recreate this error from the example given. Please comment with a fully runnable example to recreate the error you are seeing and we will reopen the issue.

The exact code I ran is below.

.eslintrc.json

{
  "plugins": [
    "cypress"
  ],
  "extends": [
    "plugin:cypress/recommended"
  ]
}

spec.js

Cypress.Commands.add('login', function () {})

it('lints', function () {
  cy.login('foo').wait(5000)
})

package.json

  "devDependencies": {
    "cypress": "4.0.1",
    "eslint": "^6.8.0",
    "eslint-plugin-cypress": "^2.9.0"
  }

@aparajita
Copy link

Please open this again, it fails with constructions like this:

import { QUICK_ANIMATION_DURATION } from '../../../../../constants/ui'

// and later...
cy.wait(QUICK_ANIMATION_DURATION)

The rule is failing here:

  const param = definition.node.params[definition.index]

because definition for the constant is of type "ImportBinding", which does not have a params property.

@jsifalda
Copy link

still an issue... 👍

@ehaughee
Copy link

ehaughee commented Sep 9, 2020

I am also still seeing this issue in the same way as @aparajita. Only difference is mine is called on the return of a then call: cy.document().then(...).wait(MY_WAIT_TIME);. My assumption is that it's a version issue. I can't easily test right now but I'd wager it does not fail this way for later versions of dependencies although eslint-plugin-cypress does theoretically test against ESLint v6. Removing these waits causes the tests to fail (I'd love to refactor these such that a wait was unnecessary, or at least find out why it is right now, I just don't have the bandwidth to do so).

Versions:
Node: 8.17.0
Cypress: 4.8.0
ESLint: 6.8.0
eslint-plugin-cypress: 2.11.1

@hkang1
Copy link

hkang1 commented Sep 17, 2020

+1 for getting the same issue, very similar to @aparajita where I'm importing a constant to determine how much to cy.wait on.

import { DEFAULT_WAIT_TIME } from '../constants';

describe('Test Suite', () => {
  it('should do x...', () => {
    /* eslint-disable-next-line cypress/no-unnecessary-waiting */
    cy.wait(DEFAULT_WAIT_TIME);
  });
});

Node: 12.18.0
Cypress: 4.8.0
ESLint: 7.5.0
eslint-plugin-cypress: 2.11.1

@mariotsi
Copy link

mariotsi commented Feb 1, 2021

Same issue for me except that the variable I'm waiting on is a Network stub alias imported from another file.

Node: 12.16.1
Cypress: 5.3.0
ESLint: 6.6.0
eslint-plugin-cypress: 2.7.0

Using Typescript

@woodi3
Copy link

woodi3 commented Mar 2, 2021

Are there any updates on this? Running into the same issue as @aparajita.

Node: 14.16.0
Cypress: 6.2.1
ESLint: 7.18.0
eslint-plugin-cypress: 2.11.2

@jennifer-shehane
Copy link
Member

Can someone provide a reproducible example? Like a repo to recreate? Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

@chozandrias76
Copy link

chozandrias76 commented Apr 15, 2021

Can someone provide a reproducible example? Like a repo to recreate? Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

Yes:

module.exports = {
  foo: 1
}
import * as cy from "cypress";
import { foo } from "index";
describe("Going to the Org Summary page", () => {
  it("does something", ()=>{
    cy.wait(foo);
  })
})
{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "plugin:cypress/recommended"
    ],
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "cypress"
    ],
    "rules": {
    }
}
~/DearestIndigoServer$ npx eslint index.spec.js

Oops! Something went wrong! :(

ESLint: 7.24.0

TypeError: Cannot read property 'null' of undefined
Occurred while linting /home/runner/DearestIndigoServer/index.spec.js:5
    at isIdentifierNumberConstArgument (/home/runner/DearestIndigoServer/node_modules/eslint-plugin-cypress/lib/rules/no-unnecessary-waiting.js:72:39)
    at CallExpression (/home/runner/DearestIndigoServer/node_modules/eslint-plugin-cypress/lib/rules/no-unnecessary-waiting.js:22:15)
    at /home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/node-event-generator.js:256:26)
    at NodeEventGenerator.applySelectors (/home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/node-event-generator.js:285:22)
    at NodeEventGenerator.enterNode (/home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/node-event-generator.js:299:14)
    at CodePathAnalyzer.enterNode (/home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
    at /home/runner/DearestIndigoServer/node_modules/eslint/lib/linter/linter.js:954:32

Edit:
Is lintable.

import * as cy from "cypress";
import {foo} from "index";
const bar = foo;
describe("Going to the Org Summary page", () => {
  it("does something", ()=>{
    cy.wait(bar);
  })
})

@MaurizioVacca
Copy link

MaurizioVacca commented Dec 6, 2021

+1 for getting the same issue, very similar to @aparajita where I'm importing a constant to determine how much to cy.wait on.

import { DEFAULT_WAIT_TIME } from '../constants';

describe('Test Suite', () => {
  it('should do x...', () => {
    /* eslint-disable-next-line cypress/no-unnecessary-waiting */
    cy.wait(DEFAULT_WAIT_TIME);
  });
});

Node: 12.18.0 Cypress: 4.8.0 ESLint: 7.5.0 eslint-plugin-cypress: 2.11.1

In case someone is having the same issue of @hkang1, I solved by re-assigning the constant:

// this causes an error while running lint
cy.wait(MY_CONST); 

// this will be accepted while running lint
const myConst = MY_CONST;
cy.wait(myConst);

Hope it helps,

Best!

@DanaGoyette
Copy link

I just ran into this when I tried to overwrite the cy.wait command to add @ if it's passed a string that doesn't start with @, allowing me to clean up my test code:

- cy.wait('@' + OPERATION_NAME).then(({ request, response }) => {
+ cy.wait(OPERATION_NAME).then(({ request, response }) => {

So that suggests a workaround of doing something similar: cy.wait('' + WHATEVER_CONST).
I've stashed my changes for now.

@walaszczykm
Copy link
Contributor

I have given it a try and opened a PR with the update to the rule code so it can properly handle ImportBindings: #109

@nagash77
Copy link
Contributor

🎉 This issue has been resolved in version 2.13.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.