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

Is it possible to return the response data as a string? #148

Open
davidatthepark opened this issue Jun 23, 2018 · 6 comments
Open

Is it possible to return the response data as a string? #148

davidatthepark opened this issue Jun 23, 2018 · 6 comments
Labels

Comments

@davidatthepark
Copy link

davidatthepark commented Jun 23, 2018

mock.onGet('/api').reply(200, '{"test": 5}')

response.data is a JS object that looks like {test: 5} instead of a string.

Is there any way to force the response to be a string?

@jeroensak
Copy link

i'd also like to use an array instead of an object. The second parameter of reply should be any type

@ctimmerm ctimmerm added the test label Jan 4, 2019
@mohit-pandey
Copy link

@ctimmerm any update or fix on how to send an array as a data?
I am a bit struggling with it.

@simon25608
Copy link

nothing news?

@joebowbeer
Copy link
Contributor

joebowbeer commented May 24, 2020

The axios default transformResponse parses strings to json objects.

If you don't want this to happen, replace transformResponse in the config.

@sdauxing
Copy link

try this
mock.onGet().replyOnce((config) => { config.transformResponse = [function (data) { return JSON.stringify(data) }] return [ 200, {test: 5} ] })

@jamespearson
Copy link

try this mock.onGet().replyOnce((config) => { config.transformResponse = [function (data) { return JSON.stringify(data) }] return [ 200, {test: 5} ] })

This won't work if the transformResponse is the thing you want to test.

At the moment, it appears a custom transformResponse on the request is called, but the data isn't passed to it. I'm going to investigate further.

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

No branches or pull requests

8 participants