skip to Main Content

I am using Cypress version 12.17.1 with VS Code in Windows 10.

I am trying to write cypress code in Visual Studio Code, but the problem I am facing is that the cypress commands starting with cy are not suggested as auto-complete (intellisense). For eample, in the below image, the suggestions in should('') only show when I require the cypress.

cypress-intellisense-vscode

Above suggestions only work if I explicitly import the cypress as:

const cypress = require("cypress")

But if I include the above statements in my cypress test file e.g. e2e/test.cy.js, then I get the error Cypress: process is not defined when I try to run my tests.
So basically every time I want to run my tests, I have to delete this line and then run the tests.
Is there a way to avoid the above error, or get the cypress suggestions to work without requiring the cypress package?

2

Answers


  1. Chosen as BEST ANSWER

    I got the issue to resolve by adding the following line at the top to enable intellisense for Cypress JS in VS Code:

    /// <reference types="Cypress" />
    

    This answer helped me: https://stackoverflow.com/a/52440156/7673215


  2. You can also add a jsconfig.json to the project root. I use

    {
      "compilerOptions": {
        "types": ["cypress", "./cypress/support/index.d.ts"]
      }
    }
    

    where the entry for "cypress" is the types defined by Cypress, and the entry for "./cypress/support/index.d.ts" is for custom commands defined in the project.

    Or Cypress mentions a "dummy" tsconfig.json here cypress-example-todomvc

    {
      "compilerOptions": {
        "lib": ["es2015", "dom"],
        "allowJs": true,
        "noEmit": true,
        "types": [
          "cypress"
        ]
      },
      "include": [
        "cypress/**/*.js"
      ]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search