Search code examples
javascriptcypressgitlab-citypeerror

Gitlab is throwing TypeError: cy.login is not a function


When I run the tests in local they work perfectly. I did the push to my pipeline and now it doesn't work and this error appears.

This is the error I'm having in my pipeline

TypeError: cy.login is not a function
Because this error occurred during a before each hook we are skipping the remaining tests in the current suite

enter image description here

This is my test: enter image description here

Commands.js: enter image description here

e2e.js: enter image description here


Solution

  • It looks like a Typescript error, although you are using .js extensions and not .ts. If Gitlab is applying the type checking, try to define the type of the cy.login() custom command.

    Here is the doumentation Types for Custom Commands

    // cypress/support/index.ts
    declare global {
      namespace Cypress {
        interface Chainable {
          login(username: string, password: string): Chainable<any>
        }
      }
    }