Use Stronger Assertions

preview_player
Показать описание
You should also strive to write the strongest assertion possible in your Cypress tests. For example, when checking a phone number, it is not enough to confirm it is a string and length. You probably want to check its format, or even assert the exact expected value

// the weakest assertion
.invoke('text')
.should('be.a', 'string')
// a much stronger assertion
const phoneFormat = /^\(\d{3}\) \d{3}-\d{4}$/
// the strongest is to confirm the exact value

Рекомендации по теме
Комментарии
Автор

Thanks for all these VERY USEFUL videos !

othmane
Автор

Wow.
Never thought about 2nd assertion. Really useful in practical cases

defender
Автор

Thank you for this. Short but sweet. :)

metamarcus
Автор

You type regex like it's your native tongue. Not even a cheat sheet in sight 😂 #goals

david
Автор

For me, anything else than cy.contains('(123) 456-7890') is ambiguous and loses "test as a documentation" property.
So it is not only about strong assertions (to avoid false negatives) but also about reading spec as a definitive story.

TuxujPes