For my unit tests I intercept all requests and then responding with mocked date for specific endpoints. I have a pageMockedRequests
function that will switch on the endpoint.
My issue comes when I want to change the response I am sending back depending on how many times it has been called.
const pageMockedRequests = (request) => {
switch (request.url()) {
case ENDPOINTS.A:
return request.respond(jsonResponseWrapper(returnValidToken(), 200));
case ENDPOINTS.B:
if (count === 0) {
return request.respond(jsonResponseWrapper({RESPONSE FOR 1st CALL}, 200));
} else if (count === 1) {
return request.respond(jsonResponseWrapper({RESPONSE FOR 2nd CALL}, 200));
}
default:
return request.abort();
}
};
The above shows that ENDPOINT.B
for the second time will be different from the first response. I'm currently changing it on count
.
Is anyone else doing this differently?