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.

Error while using nocks

See original GitHub issue

Hey, I am receiving the following error when I’m trying to post a multipart form data from nock.

Failed: Cannot read property 'status' of undefined
TypeError: Cannot read property 'status' of undefined
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/dist/apisauce.js:205:49
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/node_modules/ramda/src/cond.js:42:30
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/node_modules/ramda/src/internal/_arity.js:5:45
    at getProblemFromError (/Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/dist/apisauce.js:206:186)
    at convertResponse (/Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/dist/apisauce.js:174:29)
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/node_modules/ramda/src/internal/_createPartialApplicator.js:8:17
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/node_modules/ramda/src/internal/_arity.js:5:45
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/node_modules/ramda/src/internal/_pipe.js:3:27
    at /Users/vcashik/workspace/ReactNativeApp/node_modules/apisauce/node_modules/ramda/src/internal/_arity.js:5:45
    at tryCallOne (/Users/vcashik/workspace/ReactNativeApp/node_modules/promise/lib/core.js:37:12)

This error is weird and I am breaking my head for a day on this. I hope that someone can help before I fix my head.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ashik94vccommented, Apr 21, 2017

Hey, I just added a simple validation in getProblemFromError() to check whether the error has a response or not.

1reaction
budowskicommented, Jan 30, 2022

(For anyone getting from Google and trying to make apisauce work with nock in React Native:

jest.mock( "apisauce", ( ) => ( {
  create: (config) => {
    let axiosInstance = jest.requireActual('axios').create(config);
    const apisauce = jest.requireActual('apisauce');
    return apisauce.create({ ...config, axiosInstance });
  }
} ) );

We basically override apisauce.create method, add forcefully add an axios instance -> which then allows us to use nock.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test error in request with Nock? - Stack Overflow
I want to test the error in a request return. I'm using nock in my tests, how can I force Nock to provoke...
Read more >
Why nock throw error `Nock: No match for request ... - GitHub
When you use mocking api once then it removed. use persist ...
Read more >
nock.Interceptor.replyWithError JavaScript and Node.js code ...
Best JavaScript code snippets using nock.Interceptor. ... it('throws correct error with request error', async function () { nock(this.
Read more >
No match error when testing an Express.js controller doing ...
I had a controller requesting the same backend service but onto 2 different endpoints. My intent was to mock these calls using the...
Read more >
How to use the nock.isDone function in nock - Snyk
To help you get started, we've selected a few nock examples, based on popular ways it is used in ... isDone()) { console.error('pending...
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