MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / mockRoute

Method mockRoute

lib/helper/Puppeteer.js:2798–2809  ·  view source on GitHub ↗

* Mocks network request using [`Request Interception`](https://pptr.dev/guides/network-interception) * * ```js * I.mockRoute(/(\.png$)|(\.jpg$)/, route => route.abort()); * ``` * This method allows intercepting and mocking requests & responses. [Learn more about it](https://pptr.dev/g

(url, handler)

Source from the content-addressed store, hash-verified

2796 * @param {function} [handler] a function to process request
2797 */
2798 async mockRoute(url, handler) {
2799 await this.page.setRequestInterception(true)
2800
2801 this.page.on('request', interceptedRequest => {
2802 if (interceptedRequest.url().match(url)) {
2803 // @ts-ignore
2804 handler(interceptedRequest)
2805 } else {
2806 interceptedRequest.continue()
2807 }
2808 })
2809 }
2810
2811 /**
2812 * Stops network mocking created by `mockRoute`.

Callers 4

Playwright_test.jsFile · 0.45
Puppeteer_test.jsFile · 0.45

Calls 1

handlerFunction · 0.85

Tested by

no test coverage detected