v1.4.0
Custom Response Properties
This update adds the much-desired ability to customize the properties of your mocked responses! Includes everything from HTTP headers to fields in the XMLHttpRequest
/fetch Response
objects themselves.
Simply add your desired fields in the new responseProperties
object, and they will permeate through both XHR/response objects.
For example:
const myUrl = '/my/url';
MockRequests.setDynamicMockUrlResponse(myUrl, {
response: { error: 'You must input a valid email address' },
responseProperties: {
ok: false,
headers: {
status: 400,
},
},
});
const res = await fetch(myUrl, { ...options });
console.log(res.ok); // false
console.log(res.headers.get('status')); // 400
Support Fetch API's response.clone()
Function
This also adds support for (await fetch(...)).clone()
to ensure all your source/test code using the .clone()
function works as expected.