I am new to Cypress, and trying to write an assertion for some text inputs for a username. A valid text for a username should fulfill two conditions, which are,
- Text should contain ONLY English letters.
- Text length should be greater than 1, and less than 20.
My code is as follows.
getUserFirstName(textInput) {
cy.get('[testid="user-self-update-form"]')
.get('input[name="firstName"]')
.clear()
.type(textInput)
.blur()
.invoke('val')
.should(($el) => {
expect($el).to
.match(/[a-zA-Z]+$/)
.to
.have
.greaterThan(1)
.to
.be
.lessThan(20)
}).then(() => {
cy.log("Invalid text input");
})
}
My requirement: When a username text is inserted, the above test should check whether it meets with imposed conditions, if not, log a message in the console. I am now trying to do the above test for 4 inputs separately, which are 'abcd123', '123', 'textwithmorethantwentyletters', and 'belowtwenty'. When running this test for the first input text of 'abcd123'. How may I correct this code? Highly appreciate your help.
I get the following error, and the test is failed:

