Testing · Middle · Question 19 of 75

How do you make one test get a 500 error from an endpoint with MSW?

server.use(
  http.get("/api/user", () => new HttpResponse(null, { status: 500 })),
);

Explanation

Runtime handlers take priority over the initial ones - a neat way to test error states.

Further reading

Problem with a question

Testing · Middle · question 19

Test yourself

Take the Testing · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz