How can I send ReadableStream as a mocked response body? #1769
Answered
by
kettanaito
kyawswarthwin
asked this question in
Q&A
-
How can I send ReadableStream as a mocked response body? |
Beta Was this translation helpful? Give feedback.
Answered by
kettanaito
Oct 15, 2023
Replies: 1 comment
-
Hi, @kyawswarthwin. We add the support for import { http, HttpResponse } from 'msw'
http.get('/resource', () => {
const stream = new ReadableStream({
start(controller) {
// write chunks, don't forget to encode.
}
})
// Send back the stream response.
return new HttpResponse(stream)
})
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kettanaito
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @kyawswarthwin. We add the support for
ReadableStream
mocked responses in MSW 2.0 (msw@next
right now). This is how you can use it:ReadableStream
is a global API in the browser and Node.js (v18+).