Reputation: 6213
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.
Upvotes: 13
Views: 19553
Reputation: 630
Something like this would also work:
cy.get('input')
.invoke('val')
.then(value => assert.isTrue(!!value));
Upvotes: 1
Reputation: 6213
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).
Upvotes: 42
Reputation: 3741
there are multiple solutions, you can also use:
cy.('input').should('not.be.empty')
It's more robuust than indeed checking if the value is not an empty string.
Upvotes: -2