Uploaded March 2025 | Updated September 2026, 1 week ago
Cypress E2E tests can mock network calls or method calls, as long as we have the reference to the object being called. In this example, I mock the "EmployeesAPI.get" method my route component is making to load a list of employees. Find the full source code in the repo github.com/bahmutov/my-router-app and see more "cy.stub" examples at glebbahmutov.com/cypress-examples/commands/spies-stubs-clocks.html
Cypress E2E tests can mock network calls or method calls, as long as we have the reference to the object being called. In this example, I mock the "EmployeesAPI.get" method my route component is making to load a list of employees. Find the full source code in the repo github.com/bahmutov/my-router-app and see more "cy.stub" examples at glebbahmutov.com/cypress-examples/commands/spies-stubs-clocks.html






![Escape Regular Expression Text When Using cy.contains Command
This video shows how to escape special characters like $, [], and ^ when creating regular expressions to use with cy.contains command. You can escape the characters yourself or use the Lodash method Cypress._.escapeRegExp bundled with Cypress to do it for you
const suffix = $/day
const regex = new RegExp(Cypress._.escapeRegExp(suffix))
cy.contains(regex).should(have.id, rate)
Find the full recipe at https://glebbahmutov.com/cypress-examples Escape Regular Expression Text When Using cy.contains Command](https://i.ytimg.com/vi/hMzqiSUVGwA/mqdefault.jpg)



