request
Allows you do modify requests the browser makes during the session. This can be useful for the following use cases:
- validating if your application sends correct request payloads
- passing through authorization headers to test protected resources
- setting session cookies to test user authentication
- modifying requests to test edge cases
Usage
mock.request({ header, cookies, method, url, header, statusCode, fetchResponse })
Parameters
Name | Type | Details |
---|---|---|
overwrites | MockOverwrite | payload to overwrite the response |
overwrites.header | Record<string, string> | overwrite specific headers |
overwrites.cookies | Record<string, string> | overwrite request cookies |
overwrites.method | string | overwrite request method |
overwrites.url | string | overwrite request url to initiate a redirect |
params optional | MockResponseParams | additional respond parameters to overwrite |
params.header optional | Object | overwrite specific headers |
params.statusCode optional | Number | overwrite response status code |
params.fetchResponse optional | Boolean | fetch real response before responding with mocked data |
Example
respond.js
it('adds an auth header to my API requests', async () => {
const mock = await browser.mock('https://application.com/api', {
method: 'get'
})
mock.request({
headers: { 'Authorization': 'Bearer token' }
})
await browser.url('https://application.com')
// ...
})