where does cy variable coming from in cypress

Viewed 7281

I am have installed ESlint in out test project and it started to show me few errors that i need to resolve

one of the error is in cy.request('someURL');

The error is cy is undefined

so I have added a import statement on top of file like this

import { cy } from 'cypress';

After adding this statement none of the requests are going through I am getting this error when i try executing the tests.

Error

Tests are executing perfects once i remove the import statement

where am i going wrong

2 Answers

cy is a global variable. Much like location. So really it is window.cy. You can add it to the globals in Eslint. Don't import cy from cypress.

{
    "globals": {
        "cy": true
    }
}
/* global cy */

import above in your test file (cypress test file ex: cypress/integration/login.js

Related