I am implementing a custom Cypress command in TypeScript:
// support/commands.ts
const login = () => {
console.log(\'Logging in...\');
};
Cypress.Command
I had the same issue and all solutions I found did not work for me. Having done everything from the official Cypress documentation and other solutions here I still got the error cy.login is not a function
.
The problem was that I renamed every .js
file to .ts
and cypress/support/index.ts
was not loaded any more, because per default Cypress only loads the JavaScript one. To fix it, you need to change it to .ts
in cypress.json
like that (the same with plugins file):
{
"supportFile": "cypress/support/index.ts",
"pluginsFile": "cypress/plugins/index.ts"
}
You can also add the part with declare namespace Cypress {...
to commands.ts
instead of creating an index.d.ts
file, to have the declaration and implementation in the same file