-
Hi, I'm trying to use MSW for a simple use case, to mock some API calls in my Create-React-App application and not in tests. Just like what json-server does. According to this article it must be possible. But when I try it, it doesn't work as I expect. So maybe my expectation is wrong? What I do is I've followed the steps of the Getting-Started guide on your website taking the REST and the Browser path and doing all the instructions. Now I have this in my index.js: if (process.env.NODE_ENV === "development") {
const { worker } = require("./mocks/browser");
worker.start();
} and a I'm an absolute beginner with service workers and MSW so I cannot debug it, but is what I'm trying to do here possible at all with MSW? If yes, can you tell me where I've done wrong? return res(ctx.status(200), ctx.json(temp_obj)); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
P.S. It seems that Yes! It's possible, because here's a "working" example of it: grocery list. However, I don't understand something. It makes get requests to |
Beta Was this translation helpful? Give feedback.
-
Initially when I wrote this question I had some mistakes, but here's what I've done now and I expect it to work, but it still doesn't. I'd be glad if someone can take a look and help: codesandbox. |
Beta Was this translation helpful? Give feedback.
Initially when I wrote this question I had some mistakes, but here's what I've done now and I expect it to work, but it still doesn't. I'd be glad if someone can take a look and help: codesandbox.