This repo is a Benchmark/Explore of different/collection tools for mocking REST APIs for front-end development and testing
When it comes to mocking APIs for front-end development & testing, there are two main approaches you can consider:
- Server-Side Mocking.
- Client-Side Mocking
- Tools: (MirageJS, MSW, JSON Server, etc…)
- Manual Mocking: (writing mock data / functions in a file and importing it in the test file)
Goal ==> Explore different tools for mocking REST APIs for front-end development and testing.
Tested tools and technologies include (branch by tool):
- Mirage JS
- MSW + @mswjs/data
json-server(not tested yet)fetch-mock(not tested yet)nock(not tested yet)superagent(not tested yet)
Other tools that may be tested in the future include:
Tools and technologies used in this project are not necessarily recommended for production use.
- Node.js ( v18.16.0 used)
- Clone the repo:
$ git clone https://github.com/MidoAhmed/mock-api-explorer.git $ cd mock-api-explorer
-
Mirage JS
$ git checkout miragejs $ npm install $ npm test # run tests with jest to test the miragejs mock api server
-
MSW
$ git checkout msw $ npm install $ npm test # run tests with jest to test the MSW mock api server
Criteria | MirageJS | MSW | json-server | Nock | Fetch-mock | Superagent |
---|---|---|---|---|---|---|
Supported API | REST | REST / GraphQL | REST | REST | ||
Environments | Browser | Node / Browser | Node / Browser | Node | ||
Integration | ||||||
Definition |