Cypress Custom TypeScript Command is not a Function

后端 未结 3 1878
感动是毒
感动是毒 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:19

    Here is what I use and I do not have to add /// at the top of every file.

    I have my custom typings under /cypress/support/index.d.ts

    /// 
    
    declare namespace Cypress {
      interface Chainable {
        getByDataTest(tag: string): Chainable
      }
    }
    
    

    And my /cypress/tsconfig.json looks like

    {
      "compilerOptions": {
        "strict": true,
        "baseUrl": "../node_modules",
        "target": "es5",
        "lib": ["es5", "dom"],
        "typeRoots": ["./support"]
      },
      "include": ["**/*.ts"]
    }
    

    And TypeScript is finally happy

    describe('when I want to select by data test tag', () => {
      it('should select by data test tag', () => {
        cy.getByDataTest('yolo').should('exist')
      });
    });
    

提交回复
热议问题