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.

Mock relative (root) URL

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

3reactions
danriticommented, Dec 8, 2016

I ran into this exact problem and solved it by using the fetch-mock library instead of nock:

https://github.com/wheresrhys/fetch-mock/

2reactions
persoconcommented, Jun 15, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative URL as hostname in Nock - Stack Overflow
I'm using isomorphic-fetch in the client side and I'm using mocha and nock for testing and mocking. All my client requests are based...
Read more >
Mock Service Worker - Using Base URL - YouTube
Using Base URL — Mocking REST API with Mock Service Worker ... like "gitHubApi" to resolve relative paths to absolute service URLs.
Read more >
How to specify the base URL for all relative URLs in a ...
In the below code, we have set “https://www.geeksforgeeks.org/” as the root URL for every relative URL on the page.
Read more >
Request matching - Basics - Mock Service Worker Docs
Note that relative URL are resolved against the current location ( location.origin ). Path. Mock Service Worker uses an Express-like path syntax ...
Read more >
Manual Mocks - Jest
If the module you are mocking is a Node module (e.g.: lodash ), the mock should be placed in the __mocks__ directory adjacent...
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