mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
Co-authored-by: Frederik Rabøl <[email protected]> Co-authored-by: Christoph Fricke <[email protected]> Co-authored-by: Piotr <[email protected]> Co-authored-by: Kristján Oddsson <[email protected]> Co-authored-by: thepassle <[email protected]> Co-authored-by: Kevin Østerkilde <[email protected]> Co-authored-by: Laryssa Rocha <[email protected]> Co-authored-by: Matthew Costabile <[email protected]>
52 lines
1020 B
TypeScript
52 lines
1020 B
TypeScript
import { http, HttpResponse } from 'msw'
|
|
import { setupWorker } from 'msw/browser'
|
|
|
|
const worker = setupWorker(
|
|
http.get<{ maxCount: string }>('/polling/:maxCount', function* ({ params }) {
|
|
const { maxCount } = params
|
|
let count = 0
|
|
|
|
while (count < Number(maxCount)) {
|
|
count += 1
|
|
|
|
yield HttpResponse.json({
|
|
status: 'pending',
|
|
count,
|
|
})
|
|
}
|
|
|
|
return HttpResponse.json({
|
|
status: 'complete',
|
|
count,
|
|
})
|
|
}),
|
|
|
|
http.get<{ maxCount: string }>(
|
|
'/polling/once/:maxCount',
|
|
function* ({ params }) {
|
|
const { maxCount } = params
|
|
let count = 0
|
|
|
|
while (count < Number(maxCount)) {
|
|
count += 1
|
|
|
|
yield HttpResponse.json({
|
|
status: 'pending',
|
|
count,
|
|
})
|
|
}
|
|
|
|
return HttpResponse.json({
|
|
status: 'complete',
|
|
count,
|
|
})
|
|
},
|
|
{ once: true },
|
|
),
|
|
http.get('/polling/once/:maxCount', () => {
|
|
return HttpResponse.json({ status: 'done' })
|
|
}),
|
|
)
|
|
|
|
worker.start()
|