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]>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
// @vitest-environment node
|
|
import { http, HttpResponse } from 'msw'
|
|
import { setupServer } from 'msw/node'
|
|
|
|
const server = setupServer(
|
|
http.post('http://localhost/blob', async ({ request }) => {
|
|
return new HttpResponse(await request.blob(), {
|
|
headers: request.headers,
|
|
})
|
|
}),
|
|
)
|
|
|
|
beforeAll(() => {
|
|
server.listen()
|
|
})
|
|
|
|
afterEach(() => {
|
|
server.resetHandlers()
|
|
})
|
|
|
|
afterAll(() => {
|
|
server.close()
|
|
})
|
|
|
|
it('sends a request blob and reads the request body as blob', async () => {
|
|
const blob = new Blob(['Wello', 'world'], {
|
|
type: 'application/octet-stream',
|
|
})
|
|
const response = await fetch('http://localhost/blob', {
|
|
method: 'POST',
|
|
body: blob,
|
|
})
|
|
|
|
expect.soft(response.status, 'Returns a mocked response').toBe(200)
|
|
await expect(response.blob()).resolves.toEqual(blob)
|
|
})
|
|
|
|
it('sends a request blob with control characters', async () => {
|
|
/**
|
|
* @see https://github.com/mswjs/msw/issues/1859
|
|
*/
|
|
const blobWithControlCharacters = new Blob(
|
|
[
|
|
`0.1.0 |