With Testcafe, I have the capability to simulate the response of a request successfully.
I am interested in setting up a caching system for all GET/Ajax requests.
The current setup functions properly when the URL is already cached, but it fails to provide a response for URLs not found in the cache.
I suspect that this issue arises because I may not be calling res.setBody() for those URLs not present 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)
}
})
Is there a way to access the original Response.body
so that I can use res.setBody(originalBody)
?