The Maestro Tests App (ISTQB, A4Q, etc.) is now available on Google Play!

Cypress spies, stubs and clocks

Practice Example for cy.spy:

The idea behind this example is that when a user clicks on the like or dislike button, both buttons will disappear, and a Google Analytics event will be sent using the Google Tag Manager. Additionally, a confirmation message will appear.
Using Cypress, we can not only verify the confirmation message but also spy on the "gtag" function and assert that it was called with the correct arguments.

Practice Example for cy.stub:

For this example, when a user clicks on the "Find My Location" button, they will be prompted to grant permission for accessing their location. Once permission is granted, the coordinates will be used to make an API call and retrieve additional details about the user's country and location. These location details will then be displayed, and a typical testing scenario should verify the accuracy of this information.
With Cypress, we can simplify the testing process by stubbing the latitude and longitude coordinates. This allows us to easily simulate different locations, even across different countries, during testing. By providing custom coordinates, we can ensure that the application behaves correctly and displays the expected information for each specific location.

Practice Example for cy.clock:

The idea behind this example is that when a user clicks on the "Discover This Method" button, the 6 steps of the Scientific Method will appear one after another with a 2-second interval. However, a typical test would take more than 12 seconds to complete the scenario.
With Cypress, the cy.clock and cy.tick functions can be used to control the clock during tests, making them faster. By manipulating the clock, we can execute the same scenario in 2 seconds or even less. This allows us to speed up the testing process without compromising the accuracy of the test results.

Do you know the steps of the Scientific Method ?