question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return Array from .reply(200, 'return array instead of object or string').

See original GitHub issue

Hello, 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Jul 8, 2019

Correct, this is fixed in Beta.

1reaction
modestfakecommented, Dec 22, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found