* 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)
| 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`. |
no test coverage detected