Testcafe gives you the ability to mock the response of a request, which I am able to do.
I would like to implement a caching system for all GET/Ajax request.
This works fine if the URL is in the cache but for those that are not in the cache it returns an empty response.
This is because (I imagine) I am not calling res.setBody() on those URL not found in the cache.
export const requestMock = RequestMock()
.onRequestTo({ method: 'GET', isAjax: true })
.respond(async (req: Request, res: Response & { setBody: Function }) => {
const url: string = req.url
try {
const body: string = await cache.getItem(url)
if (body) {
res.setBody(body)
}
} catch (error) {
print.error(error)
}
})
How can I get the original Response.body
this way I can res.setBody(originalBody)
?