I have a field name
where the value 1
is not allowed. Per JavaScript I insert the text 'This value is not valid' in form
-element when the cursor left the name
-field.
I would like to test this.
I have tried this code:
cy.get('#name').clear().type('1')
cy.get('#street').trigger('click')
cy.get('#street').focus().then(() => {
cy.get('#form').should('contain.text', 'This value is not valid')
})
Sometimes the test works, sometimes not. In the application itself, the validation works without any problems.
What do I need to do to make sure the code tests valid?