I'm trying to mock calls to /users, so requests are going to the root. When I try to do:
nock('').get('/users');
I get TypeError: Cannot read property 'replace' of null.
short answer, you can't.... you have to have a http://something, you could call localhost, you could call the final API url, but you have to have a url :( struggled on that a few weeks ago to test some async actions with redux and redux-thunk
@persocon If I understand you correctly does that mean that the URL is arbitrary?
I'm in the process of writing some tests for my redux action creators that return thunks and make relative API calls using isomorphic-fetch.
@creativetim yes, ahm if I run the test on travis-ci for instance, it doens't have access to the API at all, because it is localhost right, what's happening is that Nock is always trying to hit the API and failing because it can't find... makes sense what I'm trying to explain?
@creativetim I did this for the test: https://github.com/persocon/destiny-weekly/blob/master/test/actions/user.spec.jsx#L85
and on the action: https://github.com/persocon/destiny-weekly/blob/master/src/app/javascript/actions/user.jsx#L18
I have a url option just for the tests
BUUUUT it raised a new issue: https://github.com/node-nock/nock/issues/583 it's trying to hit the real API haha even when I disable the thing
I ran into this exact problem and solved it by using the fetch-mock library instead of nock:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it鈥檚 related. Thank you!