Skip to content

Instantly share code, notes, and snippets.

@roni5
Forked from marta-pinkowska/msw.test.tsx
Created February 20, 2023 17:10
Show Gist options
  • Select an option

  • Save roni5/037e4c521338425f24e1f78d8b8dc5df to your computer and use it in GitHub Desktop.

Select an option

Save roni5/037e4c521338425f24e1f78d8b8dc5df to your computer and use it in GitHub Desktop.
// src/mocks/handlers.js
import { rest } from "msw";
export const handlers = [
// Handles a POST request
rest.post("https://fancy-app.com/postToThisEndpoint", (req, res, ctx) => {
return res(
// Respond with a 200 status code
ctx.status(200)
);
}),
// Handles a GET request
rest.get("https://fancy-app.com/getSomeData", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
data: "fancy data string",
})
);
}),
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment