Return Array from .reply(200, 'return array instead of object or string').
See original GitHub issueHello, i am working with mocha testing, and using nock to mock a get request which returns data in form of an array.
3rd Part Api returns data (in form of array):
[
{
"name": "Stamps.com",
"code": "stamps_com",
"accountNumber": "SS123",
"requiresFundedAccount": true,
"balance": 24.27,
"nickname": null,
"shippingProviderId": 12345,
"primary": true
}
]
So, to mock above data, i am trying to do
let mockCarriers = [
{
"name": "Stamps.com",
"code": "stamps_com",
"accountNumber": "SS123",
"requiresFundedAccount": true,
"balance": 24.27,
"nickname": null,
"shippingProviderId": 12345,
"primary": true
},
]
nock(apiUrl).get('/carriers').reply(200, mockCarriers).persist();
But, instead of taking it as an array, it takes it as a string. After researching, i found this : https://github.com/nock/nock#specifying-replies that states the replies that can be set over reply method.
So, i am wondering, if this is possible to return array instead of object from the reply method ?
Open to suggestions. Please suggest. Thank you.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Laravel grouped collection returns object instead of array
Laravel grouped collection returns object instead of array ; just send it return response()->json($outings, 200);. – rkj. Jun 28, 2018 at 15:56.
Read more >I want to return Array from script include and use... - ServiceNow
Solved: client script var ga = new GlideAjax('TASK_return_array_SI'); ga.addParam('sysparm_name', 'getCallerDetails'); ga.addParam('sysparm_inc',
Read more >Object returned from API call causes "Invalid API Response:
The API I am working with returns results as an object, not an array like Zapier expects. I am using Code Mode in...
Read more >How to Return an Array in a C++ Function - DigitalOcean
Typically, returning a whole array to a function call is not possible. We could only do it using pointers. Moreover, declaring a function...
Read more >5. Working with Arrays and Loops - JavaScript Cookbook [Book]
In JavaScript, an array can be created using formal object notation, or it … ... It returns a string with all of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Correct, this is fixed in Beta.
@gr2m I’ve reproduced it here https://runkit.com/modestfake/node-nock-nock-768 The problem is in this lines of code https://github.com/nock/nock/blob/v10.0.4/lib/request_overrider.js#L405-L426