how to use moxios to return streams that have images

This issue has been tracked since 2020-07-26.

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('', {
        status: 200,
        response: { data: fs.createReadStream(`${__dirname}/text.png`) }

But the When I use it does not work.

Any help appreciated for mocking a get request returning a stream object.

nzwsch wrote this answer on 2021-10-17

Just pass fs.createReadStream directly.

moxios.stubRequest('/text.png', {
  status: 200,
  response: fs.createReadStream(`${__dirname}/text.png`),
More Details About Repo
Owner Name axios
Repo Name moxios
Full Name axios/moxios
Language JavaScript
Created Date 2016-05-25
Updated Date 2022-12-05
Star Count 1386
Watcher Count 20
Fork Count 85
Issue Count 19


Issue Title Created Date Updated Date