mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
Co-authored-by: Felmon Fekadu <[email protected]> Co-authored-by: Felmon Fekadu <[email protected]>
26 lines
668 B
TypeScript
26 lines
668 B
TypeScript
import { http } from 'msw'
|
|
import { setupWorker } from 'msw/browser'
|
|
|
|
const worker = setupWorker(
|
|
http.get('/user', () => {
|
|
return new Response()
|
|
}),
|
|
)
|
|
|
|
Object.assign(window, {
|
|
msw: {
|
|
async startWorker() {
|
|
await worker.start({
|
|
serviceWorker: {
|
|
// Use a custom Service Worker for this test that intentionally
|
|
// delays the worker installation time. This allows us to test
|
|
// that the "worker.start()" Promise indeed resolves only after
|
|
// the worker has been activated and not just registered.
|
|
url: './worker.js',
|
|
},
|
|
})
|
|
},
|
|
stopWorker: worker.stop.bind(worker),
|
|
},
|
|
})
|