Understanding Cypress aliases
Aliases are a way to prevent the usage of .then()
callback functions in our tests. We use aliases to create references or some kind of "memory" that Cypress can refer to, hence reducing the need for us to re-declare the items all over again. A common use of aliases is to avoid using callback functions in our before
and beforeEach
test hooks. Aliases provide a "clean" way to access the global state of a variable without the need for calling or initializing the variable in every single test. In this section, we will learn how to properly utilize aliases in our test execution and different scenarios where using aliases is recommended.
Aliases come in handy in situations where one variable is utilized by more than one test in a test suite. The following code block shows a test where we want to verify that our to-do item does exist after we have added it to our to-do list:
context('TODO MVC - Aliases Tests', () => { &...