Skip to content

Latest commit

 

History

History
25 lines (14 loc) · 1 KB

README.md

File metadata and controls

25 lines (14 loc) · 1 KB

Karma + MSW

Mock Service Worker usage example with Karma.

Edit in CodeSandbox

Key points

1. Generate the worker script

npx msw init ./test

2. Configure Karma

Specify the base path

In karma.conf.js, add set the basePath property to ./test (the test directory). This has to be the test runner's base path in order for it to serve the worker script generated in the previous step.

Proxy the worker script request

In karma.conf.js, add a proxies property and list the /mockServiceWorker.js resource path to proxy the worker script generated in the ./test directory.

This is necessary so that root-level requests to /mockServiceWorker.js are resolved relatively to the Karma's prepended /base/ path prefix.