Cypress Custom TypeScript Command is not a Function

后端 未结 3 1881
感动是毒
感动是毒 2021-02-19 19:13

I am implementing a custom Cypress command in TypeScript:

// support/commands.ts
const login = () => {
    console.log(\'Logging in...\');
};

Cypress.Command         


        
3条回答
  •  你的背包
    2021-02-19 19:43

    I fixed it by adding index.d.ts file in my commands folder. In this file I added something like this:

    import { MyCustomType } from '../Types';
    
    declare global {
      namespace Cypress {
        interface Chainable {
          login(): Chainable;
        }
      }
    }
    

    If You don't import or export anything, just omit global namespace declaration:

    declare namespace Cypress {
      interface Chainable {
        login(): Chainable;
      }
    }
    

    Keep in mind that it won't work with Typesciprt < 2.3, becuase default generics type has to be supported.

提交回复
热议问题