How to mock an external domain/resource? #986
-
I'd like to use mswjs to mock some external APIs (not on localhost), I can't find any information online on wether this is possible or not. I need to mock both localhost resources and external resources at the same time. May someone provide an example configuration of how to do it? I'm using the Storybook addon if it matters. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, @FezVrasta. You can mock any resources that match the request handler you create. That includes both local and external resources! Our README features an example of mocking a rest.get('https://github.com/octocat', (req, res, ctx) => {
return res(
ctx.delay(1500),
ctx.status(202, 'Mocked status'),
ctx.json({
message: 'Mocked response JSON body',
}),
)
}), |
Beta Was this translation helpful? Give feedback.
Hey, @FezVrasta.
You can mock any resources that match the request handler you create. That includes both local and external resources!
Our README features an example of mocking a
GET
request to GitHub's REST API. You can also read the Request matching page in our docs to learn more about how exactly MSW matches resources.