I'm trying to setup Typescript with Cypress following the docs found here: https://docs.cypress.io/guides/tooling/typescript-support#Configure-tsconfig-json
- I already have
typescriptinstalled for my server/app. - I add a
tsconfig.jsonin thecypress/directory
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": ["**/*.ts"]
}
- I add their code in
cypress/support/index.ts:
// in cypress/support/index.ts
// load type definitions that come with Cypress module
/// <reference types="cypress" />
declare global {
namespace Cypress {
interface Chainable {
/**
* Custom command to select DOM element by data-cy attribute.
* @example cy.dataCy('greeting')
*/
dataCy(value: string): Chainable<Element>
}
}
}
- I add THEIR example command in my
commands.tsfolder, instead of the `same file as above.
// cypress/support/commands.ts (instead of index.tx)
Cypress.Commands.add('dataCy', (value) => {
return cy.get(`[data-cy=${value}]`)
})
The callback function gives me the following error:
Argument of type '(value: string) => Chainable<JQuery<HTMLElement>>' is not assignable to parameter of type '(value: string) => Chainable<Element>'.
So I update the index.ts callback function
- From
dataCy(value: string): Chainable<Element> - To
dataCy(value: string): Chainable<JQuery<HTMLElement>>
But now my index.ts has the following error:
'JQuery' is not defined.
And I cannot find anywhere/anyway to import JQuery to remove the issue.
Thanks in advance for your help.