Mocking HTTP responses and intercepting HTTP requests
Mocking tests can help us isolate and focus on tests and not on the state of external dependencies or behavior. In this section, we will mock the HTTP responses of our server and intercept the HTTP requests of our Angular application for testing. We are going to intercept the HTTP requests so that we can send fake responses to Angular and not pollute our dev database.
We will start by adding a new file to the root of the cypress
directory. Name the file global.d.ts
. The global.d.ts
file, also known as global libraries, provides a way to make interfaces and types globally available in our TypeScript code.
After creating the global.d.ts
file, write the following code inside it:
/// <reference types="cypress"/> declare namespace Cypress { interface Chainable { getCommand(url: string, responseBody: Array<any>): &...