Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.type() will not accept an empty string cypress

I want to check if the text "You must enter a value"(Screenshot attached) is present in the login screen that I have created. This appears when a user touched the input field and then clicked on a different field or area without typing anything. So I tried to test it with cypress, but it says

".type() will not accept an empty string"

Cypress:

it('Should display You must enter a value if user does not type anything', () => {
        cy.get('#username').type('')
        cy.contains('You must enter a value')
    })

I need help in fixing this, thank you.

Email Field

like image 614
PremKumar Avatar asked Jun 27 '26 16:06

PremKumar


1 Answers

Just focus and blur indeed:

it('Should display You must enter a value if user does not type anything', () => {
   cy.get('#username')
      .focus()
      .blur()
   cy.contains('You must enter a value')
})
like image 169
Mr. J. Avatar answered Jun 30 '26 09:06

Mr. J.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!