Reputation: 159
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.
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?
Upvotes: 1
Views: 2450
Reputation: 4986
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"
]
}
Upvotes: 3
Reputation: 159
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
Upvotes: 2