Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assert that input value is truthy with cypress

Tags:

cypress

I have some input

<input />

How to assert that input has truthy value?

I think it's possible with

cy('input').should('not.have.value', '')

but I think it's slightly unreliable. Or maybe not. But anyway, would be nice to know some other way to check for truthy value.

like image 483
Maksim Nesterenko Avatar asked Aug 28 '19 13:08

Maksim Nesterenko


People also ask

How do you verify text in Cypress?

Cypress can validate the text on an element with the help of jQuery text() method. This method shall help us to fetch the text content on the selected element. We can also put assertions on the text content of the element. cy.

How do you get attribute values in Cypress?

To find elements by data attribute, query using the attribute selector. cy. get() yields a jQuery object, you can get its attribute by invoking the . attr() method.

How do you know if an element is visible or not in Cypress?

The only way for you to "see" and debug why Cypress thought an element was not visible is to use a debugger statement.

What are the assertions in Cypress?

Handling Assertions in Cypress: Tutorial. For every test, it is essential to have a validation that checks whether it functions as expected or not. Assertions are these validations in the test automation, which determine whether the test is working as expected or not.


1 Answers

Just found that invoke thing, so it's possible to do so:

cy.get('input').invoke('val').should("be.ok");
cy.get('input').invoke('val').should('not.be.empty') // works in the same way.

invoke is the way to call functions (jquery command in that case).

like image 69
Maksim Nesterenko Avatar answered Oct 08 '22 17:10

Maksim Nesterenko