fetch-mock
fetch-mock copied to clipboard
fallbackToNetwork does not work with relative URLs
when fetch-mock is running with fallbackToNetwork = true, any relative URLs are always prepended with /
fetch("image.png") results in network request to "/image.png", when the index.html is not hosted on the root of the domain.
This is because of normalizeURL rebases the URL not to the current pathname:
} else {
const u = new URL(url, 'http://dummy');
return u.pathname + u.search;
}
One potential workaround for this could be
new URL(url, typeof location === "undefined" ? 'http://dummy' : location.href);
I now have a 'fix' for this being rolled out in @fetch-mock/core https://github.com/wheresrhys/fetch-mock/pull/805