moxios
moxios copied to clipboard
how to use moxios to return streams that have images
I am trying to use moxios to mock the following scenario.
axios.default.get(imageUrl, { responseType: 'stream' })
To unit test the above, I am trying to write jest with the following.
moxios.stubRequest('http://abc.com/text.jpg', {
status: 200,
response: { data: fs.createReadStream(`${__dirname}/text.png`) }
});
But the response.data. When I use response.data.pipe(somewriteablestream) it does not work.
Any help appreciated for mocking a get request returning a stream object.
Just pass fs.createReadStream
directly.
moxios.stubRequest('/text.png', {
status: 200,
response: fs.createReadStream(`${__dirname}/text.png`),
})