Skip to content

Commit

Permalink
feat(cypress): wrap commands registration within a registerMonitorUiC…
Browse files Browse the repository at this point in the history
…ustomCommands() function
  • Loading branch information
ivangabriele committed Apr 11, 2023
1 parent 5a0c394 commit 2142789
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/cypress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@ import { fill } from './commands/fill'
import { forceClick } from './commands/forceClick'
import { getDataCy } from './commands/getDataCy'

Cypress.Commands.add('clickButton', { prevSubject: 'optional' } as any, clickButton as any)
export const registerMonitorUiCustomCommands = () => {
Cypress.Commands.add('clickButton', { prevSubject: 'optional' } as any, clickButton as any)

Cypress.Commands.add(
'clickLink',
(linkText: string): Cypress.Chainable<JQuery<HTMLAnchorElement>> => cy.get('a').contains(linkText).click()
)
Cypress.Commands.add(
'clickLink',
(linkText: string): Cypress.Chainable<JQuery<HTMLAnchorElement>> => cy.get('a').contains(linkText).click()
)

/**
* @description
* Useful to close modals.
*/
Cypress.Commands.add('clickOutside', clickOutside)
/**
* @description
* Useful to close modals.
*/
Cypress.Commands.add('clickOutside', clickOutside)

/**
* @example
* ```ts
* cy.fill('Password', 'P422W0Rd')
* ```
*/
Cypress.Commands.add('fill', fill)
/**
* @example
* ```ts
* cy.fill('Password', 'P422W0Rd')
* ```
*/
Cypress.Commands.add('fill', fill)

// Maybe because of https://github.com/cypress-io/cypress/issues/19564
Cypress.Commands.add('forceClick', { prevSubject: true }, forceClick)
// Maybe because of https://github.com/cypress-io/cypress/issues/19564
Cypress.Commands.add('forceClick', { prevSubject: true }, forceClick)

Cypress.Commands.add('getDataCy', getDataCy)
Cypress.Commands.add('getDataCy', getDataCy)
}

registerMonitorUiCustomCommands()

0 comments on commit 2142789

Please sign in to comment.