Polina  Lisetska
Polina Lisetska

Reputation: 55

What is the difference between assertions in Cypress?

What is the difference between:

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

Answers (2)

pavelsaman
pavelsaman

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

Arek Khatry
Arek Khatry

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

Related Questions