MCPcopy
hub / github.com/mswjs/msw / stopWorkerOn

Function stopWorkerOn

test/browser/msw-api/setup-worker/stop.test.ts:12–36  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

10}
11
12const stopWorkerOn = async (page: Page) => {
13 page.evaluate(() => {
14 window.msw.worker.stop()
15 })
16
17 await new Promise<void>((resolve, reject) => {
18 const timeout = setTimeout(() => {
19 reject(new Error('Failed to await the worker stop console message!'))
20 }, 5000)
21
22 page.on('console', (message) => {
23 const text = message.text()
24
25 if (
26 // Successful stop console message.
27 text.includes('[MSW] Mocking disabled.') ||
28 // Warning when calling "stop()" multiple times.
29 text.includes('worker.stop()')
30 ) {
31 clearTimeout(timeout)
32 resolve()
33 }
34 })
35 })
36}
37
38test('disables the mocking when the worker is stopped', async ({
39 loadExample,

Callers 1

stop.test.tsFile · 0.85

Calls 2

textMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…