Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivstudio/mock-service-worker
API Mocking in JavaScript using Mock Service Worker (MSW) demo.
https://github.com/ivstudio/mock-service-worker
jest msw react react-testing-library
Last synced: 22 days ago
JSON representation
API Mocking in JavaScript using Mock Service Worker (MSW) demo.
- Host: GitHub
- URL: https://github.com/ivstudio/mock-service-worker
- Owner: ivstudio
- Created: 2024-08-21T15:46:30.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-10-23T22:27:52.000Z (2 months ago)
- Last Synced: 2024-10-24T11:30:30.146Z (2 months ago)
- Topics: jest, msw, react, react-testing-library
- Language: TypeScript
- Homepage: https://ivstudio.github.io/mock-service-worker/
- Size: 9.08 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# API Mocking in JavaScript using Mock Service Worker
This repository showcases a Mock Service Worker (MSW) v2 setup in a React environment, seamlessly integrated with Jest and React Testing Library. The configuration allows MSW to intercept API calls during development and unit testing, offering comprehensive control and flexibility throughout the development process.
[View the project](https://ivstudio.github.io/mock-service-worker/)
## Key Features
- [Detailed article](https://www.ivstudio.com/blog/mock-service-worker) providing a step-by-step explanation of the implementation process.
- Configuration of handlers, setupWorker, and setupServer for API mocking.
- On-demand API interception during development using MSW's browser integration.
- API interception in Jest and React Testing Library environments using MSW's Node.js integration.### Tech Stack
- [Mock Service Worker (MSW)](https://mswjs.io/) for API mocking
- [Jest](https://jestjs.io/) for unit testing
- [React Testing Library](https://testing-library.com/) for component testing
- [React](https://react.dev/) for building the UI### Getting Started
1. Clone the repository
2. Install dependencies: `npm install`
3. Run the mock API: `npm run dev:mock`
4. Start the development server: `npm run dev`### Testing
To run all tests, use the following command: `npm run test`