cy.get() how to place 2 arguments in Cypress?

  cypress, javascript

Hi,
I want to improve this code to avoid repetition ! any ideas ?

 const captureEmailModal = email => {
        When(`I type ${email.fullName}`, () => {
            cy.wait(1000)
            cy.get(email.dataCyModalFullName).should(exist)
                .type(email.fullName)
                .invoke('val')
                .should('match', /^(?! )[A-Za-zs]+$/)
            cy.get(email.dataCyModalEmail).should(exist)
                .type(email.email)
                .invoke('val')
                .should('match', /^(([^<>()[].,;:[email protected]"]
            cy.get(email.dataCyModalPhone).should(exist)
                .type(email.phone)
                .invoke('val')
                .should('match', /^[0-9]+$/)
                .should('have.length', 10)
        })

Just the email.dataCyFaqFullName / email.dataCyFaqEmail and email.dataCyFaqPhone who changes

        And(`I type ${email.fullName} in FAQ page`, () => {
            cy.wait(1000)
            cy.get(email.dataCyFaqFullName).should(exist)
                .type(email.fullName)
                .invoke('val')
                .should('match', /^(?! )[A-Za-zs]+$/)
            cy.get(email.dataCyFaqEmail).should(exist)
                .type(email.email)
                .invoke('val')
                .should('match', /^(([^<>()[].,;:[email protected]"]
            cy.get(email.dataCyFaqPhone).should(exist)
                .type(email.phone)
                .invoke('val')
                .should('match', /^[0-9]+$/)
                .should('have.length', 10)
        })
    }

Source: Ask Javascript Questions

LEAVE A COMMENT