requestOnce
Only change request parameter once with given overwrite for the next request. You can call requestOnce
multiple
consecutive times and it will apply the overwrites in order. If you only use requestOnce
and the resource is called
more times a mock has been defined than it defaults back to the original resource.
Usage
mock.requestOnce({ 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 different auth headers to my API requests', async () => {
const mock = await browser.mock('https://application.com/api', {
method: 'get'
})
mock.requestOnce({
headers: { 'Authorization': 'Bearer token' }
})
mock.requestOnce({
headers: { 'Authorization': 'Another bearer token' }
})
await browser.url('https://application.com')
// ...
})