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]>
20 lines
466 B
TypeScript
20 lines
466 B
TypeScript
import { http, HttpResponse } from 'msw'
|
|
import { setupWorker } from 'msw/browser'
|
|
import base64Image from 'url-loader!../../../../fixtures/image.jpg'
|
|
|
|
const worker = setupWorker(
|
|
http.get('/images/:imageId', async () => {
|
|
const imageBuffer = await fetch(base64Image).then((res) =>
|
|
res.arrayBuffer(),
|
|
)
|
|
|
|
return HttpResponse.arrayBuffer(imageBuffer, {
|
|
headers: {
|
|
'Content-Type': 'image/jpeg',
|
|
},
|
|
})
|
|
}),
|
|
)
|
|
|
|
worker.start()
|