0

I am attempting to include custom commands in my Cypress tests using typescript. It just seems so difficult to get it to work. I have moved the files in various folders but it is simply a frustrating experience. It shouldn't be this hard. Here is the structure of my project: I am using version 12.14.0 of Cypress and Typescript

In my support folder, I have the following files

         cypress
              support
                e2e.ts
                index.d.ts.     // declare namespace Cypress with definitions of commands 
                accounts-cmd.ts  // has Cypress.Command.add(.....)
              fixtures
              tests // my tests are in here
                accounts.cy.ts  // uses custom command findByAccountsId(id: string)
       //tsconfig.json
       types: ["cypress", "./support"]

      //cypress.config.ts
       supportFile: "./support/e2e.ts",


I have my a declaration in the index.d.ts called findAccountsById(id: string) which returns a Chainable from and axios call. It is defined like this


    findByAccountId(id: string): Chainable<Response>;


In my accounts-cmd.ts I reference the index.d.ts

    /// <reference path="./index.d.ts" />
BreenDeen
  • 623
  • 1
  • 13
  • 42

1 Answers1

4

I think you want to put the reference in includes: [] property of tsconfig.json.

See cypress-real-world-app

{
  ...
  "include": ["./**/*.ts"],  // catches /cypress/support/index.d.ts
  ...
}

My understanding is that "types" key is for node modules, not your own types.

Chrome Artie
  • 148
  • 4