msw
msw copied to clipboard
Calls to worker.use() remove handlers to same endpoint with different method
I'm trying to write dynamic handler builders, but I'm hitting this issue:
worker.use(
http.get("/v1/issues", () => HttpResponse.json(/* some json */))
)
// this will make the get handler ignored!
worker.use(
http.post("/v1/issues", () => HttpResponse.json(/* some json */))
);
I'm aware that repeated calls to worker.use prepend handlers to the existing context, and therefore order matters. But then why does this code work?
// both handlers work
worker.use(
http.get("/v1/issues", () => HttpResponse.json(/* some json */)),
http.post("/v1/issues", () => HttpResponse.json(/* some json */))
);
Since both handlers work when added in a single worker.use call, shouldn't this method take into account any methods previously added to the context so as not to remove them and provide the same end result?