Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use moxios to return streams that have images #80

Open
knihit opened this issue Jul 26, 2020 · 1 comment
Open

how to use moxios to return streams that have images #80

knihit opened this issue Jul 26, 2020 · 1 comment

Comments

@knihit
Copy link

knihit commented Jul 26, 2020

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.

@nzwsch
Copy link

nzwsch commented Oct 17, 2021

Just pass fs.createReadStream directly.

moxios.stubRequest('/text.png', {
  status: 200,
  response: fs.createReadStream(`${__dirname}/text.png`),
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants