Skip to content

Commit

Permalink
Merge pull request #4 from Synthetixio/custom-cmds
Browse files Browse the repository at this point in the history
feat: add new custom commands
  • Loading branch information
drptbl authored Dec 1, 2020
2 parents 1ff9f78 + 3304ad1 commit 4341b73
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import '@testing-library/cypress/add-commands';
import 'cypress-wait-until';

Cypress.Commands.add('getId', name => {
if (name.includes('@')) {
return cy.get(`${name}`);
}
return cy.get(`[data-testid="${name}"]`).as(name);
});

Cypress.Commands.add('getText', selector => {
return cy.getId(`${selector}`).invoke('text');
});

Cypress.Commands.add('waitUntilExist', selector => {
cy.waitUntil(() => {
return cy.getId(`${selector}`).should('exist');
});
});

Cypress.Commands.add('getDesktopSizes', () => {
return [
[1366, 768],
Expand Down
21 changes: 21 additions & 0 deletions support/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
declare namespace Cypress {
interface Chainable<Subject> {
/**
* Get element using data-testid and sets an alias for it
* @example
* cy.getId('dataTestId')
* cy.getId('alias')
*/
getId(testid: string): Chainable<Subject>;
/**
* Get text of element
* @example
* cy.getText('selector').then(text => cy.log(text))
* cy.getText('alias').then(text => cy.log(text))
*/
getText(selector: string): Chainable<Subject>;
/**
* Waits until element exists
* @example
* cy.waitUntilExist('selector')
* cy.waitUntilExist('alias')
*/
waitUntilExist(selector: string): Chainable<Subject>;
/**
* Get the most popular desktop resolutions
* @example
Expand Down

0 comments on commit 4341b73

Please sign in to comment.