Reputation: 55
What is the difference between:
cy.contains('text').should('be.visible')
; andcy.should('be.visible','text')
?Because for me the first option is working to check the text but the second it doesn't check properly, so I was wondering in which cases I can use the second option for checking the text?
Upvotes: 0
Views: 326
Reputation: 8322
cy.should()
doesn't exist, you need to yield something before you run an assertion on it. You can read more about the command here.
The syntax mentioned in the documentation:
.should(chainers)
it does not start with cy.
, so it means you have to have another command that yields something before you use .should()
.
You can compare it to what documentation mentions for cy.get()
command that could be directly chained with cy
:
cy.get(selector)
Upvotes: 8
Reputation: 35
If you read this article https://docs.cypress.io/api/commands/should.html#Usage , it's an incorrect usage of using cy.should(). So, it's better not to use second option.
Upvotes: 0