Comments (4)
Hi, @jlissner. Thanks for reporting this!
What would be the use case when the location
object exists but doesn't have the href
property set?
That sounds a lot like a broken environment then. In that case, the environment has to be fixed. The interceptor is correctly relying on the existing global location
object, which must have the href
property.
return new URL(url.toString(), location.href || undefined)
This won't work, sadly, because if url
is relative and location.href
is missing, like in your case, the URL constructor will throw anyway.
I will close this for now but would like to hear from you regarding my question above.
from interceptors.
For my example, it was a simple test of react component. The request was made to a fully qualified URL, so no base url had been set. I can try to set up a repo to reproduce, but it seems that you could repeat it fairly easily. The app was created with create-react-app
, using axios
to fetch the data (which if I set the adapter to http doesn't have this problem, but introduces other problems). Then, just create a simple test, having msw
try to mock a response from say, http://example.com
, and when you do const data = await axios({ url: 'http://example.com', method: 'GET' });
in your code, it will break.
from interceptors.
I can try to set up a repo to reproduce
Please do! I'd be happy to iterate on this together once the reproduction is here. Thanks.
from interceptors.
In working to reproduce, I found where the root of the issue was coming from :)
We needed to mock some window location methods, such as described in articles like https://remarkablemark.org/blog/2018/11/17/mock-window-location/
So, we ended up with a piece of code in our setup file that looked like this:
Object.defineProperty(global, 'location', {
value: {
assign: jest.fn(),
reload: jest.fn(),
href: '', // this was the problem
},
writable: true,
});
I agree that this SHOULDN'T happen, and I will have to dig further to understand why it happened in the first place as no including it at all works just fine, but still took hours to understand the error being given: Invalid base URL
, considering now base URL was given.
from interceptors.
Related Issues (20)
- Support HTTP2 HOT 3
- Intercepted fetch results in the the process never exiting / hangs Mocha tests
- error listener get called twice on mocked error with sync handler HOT 2
- Use "urlToHttpOptions" from "node:url"
- Header keys for requests are being converted to lowercase
- ReferenceError: TextEncoder is not defined when running (jest) tests HOT 4
- Treat exceptions as 500 responses instead of a "Failed to fetch" error HOT 7
- Support aborting intercepted requests HOT 6
- WebSocket: Outgoing client events have the wrong "currentTarget" HOT 2
- WebSocket: Decide how to handle actual server errors
- Flaky: `modules/http/response/readable-stream.test.ts`
- ClientRequestInterceptor incorrectly encodes basic authentication header HOT 15
- Abstract request emitting logic
- Await all "response" listeners to finish HOT 4
- Protocol "https:" not supported. Expected "http:" when using "proxy-agent" HOT 1
- Simplify the npm package files HOT 2
- XMLHttpRequest upload (upload.onprogress) event is not supported
- Issue with native fetch introduce after 0.25.1? HOT 2
- Pending Socket interceptor tasks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interceptors.