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