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
response body comes back with status code when a callback is passed to .reply() #2218
Comments
Hi! can you fill out the bottom of the template? |
Done |
The example you provided isn't valid JavaScript: {"THIS IS THE REPLY BODY"} |
This use case seems to work fine. I added a test case in #2219. |
Come on. I put that there just to show you that I understand that that's where the reply body should be. Of course it's an object. |
My exact use case looks something like this: nock('https://amazon.com')
.get('/search')
.reply((uri, requestBody) => {
let url new URL(`https://amazon.com${uri}`);
let searchParams = url.searchParams;
if (!searchParams.get('exactTerms')) {
return [
StatusCodes.INTERNAL_SERVER_ERROR,
companyEventsResearchResponse
];
}
return [
StatusCodes.OK,
companyEventsResearchResponse
];
}); |
Sorry, didn't mean to upset you. I was trying to determine if this is a bug in Nock, or if there was something strange about your use case that was causing this, which is why I wanted to try to reproduce the test case you reported. I added a test in #2219 which confirms that the behavior matches what you expect so I do not think this is a bug in Nock. For usage and support questions we primarily use StackOverflow. Please tag the questions with |
What is the expected behavior?
The reply callback returns an array with index 0 as status code and index 1 as response body. I expect the my api call to respond with the request body specified in index 1 and not return the entire array with the status code.
What is the actual behavior?
The entire array is with status code is returned as request response.
Possible solution
Return just the body specified in index 1
How to reproduce the issue
Runkit: Example link
Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.
Does the bug have a test case?
Versions
The text was updated successfully, but these errors were encountered: