Created
June 28, 2021 16:55
-
-
Save hscheuerle/35c21a8d41a56b182d02acbd4b538d09 to your computer and use it in GitHub Desktop.
non variadic cypress page object utility function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const dataCy = (value: string) => cy.get(`[data-cy=${value}]`); | |
export const dataCyPath = (...attrs: string[]) => cy.get(attrs.map(attr => `[data-cy=${attr}]`).join(' ')); | |
export const dataCyObject = <T extends readonly string[]>(hostAttr: string, attrs: T) => | |
attrs.reduce((cyObject, attr) => (cyObject[attr] = () => dataCyPath(hostAttr, attr)) && cyObject, {} as Record<T[number], () => Cypress.Chainable<JQuery<HTMLElement>>>); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment