Mock Service Worker usage example with Karma.
npx msw init ./test
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.
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.