intercept()
Add interceptor for the network call. Helps in overriding request or to mock response of a network call.
Examples
Section titled “Examples”# Case 1: Block a specific URLawait intercept(url)# Case 2: Mock a responseawait intercept(url, {mockObject})# Case 3: Override requestawait intercept(url, (request) => {request.continue({overrideObject})})# Case 4: Redirect alwaysawait intercept(url, redirectUrl)# Case 5: Mock response based on a requestawait intercept(url, (request) => { request.respond({mockResponseObject}) })# Case 6: Block URL twiceawait intercept(url, undefined, 2)# Case 7: Mock the response only 3 timesawait intercept(url, {mockObject}, 3)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
requestUrl | string | request URL to intercept |
option | function | Object | action to be done after interception. For more examples refer to https://github.com/getgauge/taiko/issues/98#issuecomment-42024186 |
count | number | number of times the request has to be intercepted . Optional parameter |
Returns
Section titled “Returns”| Type | Description |
|---|---|
Promise<void> |