Skip to content
Advertisement

Cypress Best Practice – Store and compare two values

I want to store a value, then perform an action and assert that the value has not changed. I do have a code that works but I would like to have input if there is a more elegant solution.

The basic idea is:

  • Get the number or results displayed (‘counts’), store it in a .then() function
  • Change the use
  • Get the number of results displayed (‘new_counts’), store it in a new .then function
  • Compare counts and new_counts in the 2nd .then() function
JavaScript

That is the best I could come up with to handle asynchronicity.

Advertisement

Answer

You can use aliases for this and do something like this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement