How to create a mock per endpoint
See original GitHub issueHey!
Is there a way to mock a endpoint based on what fetch was called with?
Example:
fetch.mockResponseOnce(
"http://api-lsdi.com/api/cart/1",
JSON.stringify(sampleResponse)
);
Basically the intention of this is to say mock this specific endpoint with this payload
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Create Rest Mock API in Seconds With These 9 Tools
Here, we will know some of the best tools to create REST mock API. ... In this platform, you can create, get, update,...
Read more >Setting up mock servers | Postman Learning Center
Select Mock Servers in the sidebar, then select +. ... Select an existing collection, or create a new collection and add an initial...
Read more >How To Create And Use Mock Apis In Minutes | Beeceptor
Mock API is a simple tool that lets you easily mock up APIs, generate custom data, and preform operations on it using RESTful...
Read more >How to make a mock API server in JavaScript - Snyk
Development: Mock API servers temporarily remove the dependency between the frontend and backend teams, allowing them to work, develop, and test ...
Read more >Docs - mockAPI
1. Create new mock project. New project form · 2. Add resource. New resource form. NOTE: Resource name maps to the endpoint url....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
fetch.mockResponse
takes in either the response or a function that accepts the request and generates the response. So you can do exactly like you say by writing a switch statement in the function. Just see the docs or the TypeScript definition.Currently there isn’t. I’m trying to work through a PR by @yinzara to get this done. You can check out the code here and see if it would fit your usecase:
https://github.com/jefflau/jest-fetch-mock/pull/123