Home > OS >  How to make custom cypress commands work with typescript
How to make custom cypress commands work with typescript

Time:11-18

I have set up the following example repo following the example code from the documentation of Cypress both for setting up the project and adding typescript to it to the letter: enter image description here

and in commands.ts:

enter image description here

CodePudding user response:

Did you try with the following?

declare global {
  namespace Cypress {
    interface Chainable<Subject> {
      dataCy(value: string): Chainable<Element>;
    }
  }
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

You should add the namespace inside the global declaration. It is working for me correctly.

I am using Cypress v8.7.0 and Typescript v4.1.3.

  • Related