URL constructor is missing 'base' option
See original GitHub issueThe URL constructor at https://github.com/capricorn86/happy-dom/blob/57a8d33d4b1ba3bdd4df0f7f8bc02e0d06bd8e9e/packages/happy-dom/src/location/URL.ts#L23 does not support the second form of the URL constructor which takes a base
url:
new URL(url)
new URL(url, base)
Quick test:
# expected
> new URL('', 'https://example.com').pathname
'/'
# actual
> new URL('', 'https://example.com').pathname
''
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:12 (9 by maintainers)
Top Results From Across the Web
URL() - Web APIs - MDN Web Docs - Mozilla
The URL() constructor returns a newly created URL object representing the URL defined by the parameters.
Read more >URL parse vs constructor: path missing - Stack Overflow
So if anything the constructor seems to provide a better break down of the URL. I don't why, when I try to copy...
Read more >URL (Java Platform SE 7 ) - Oracle Help Center
Creates a URL object from the String representation. This constructor is equivalent to a call to the two-argument constructor with a null first...
Read more >URL | Node.js v19.3.0 Documentation
The URL constructor is accessible as a property on the global object. ... The url.format(URL[, options]) method allows for basic customization of the...
Read more >MongoClient or how to connect in a new and better way
The main difference is that the constructor is missing the database name from Db. ... MongoClient supports the same options as the previous...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After a lot of debugging, I stumbled upon the same issue. In my case I was trying to replace jsdom by happydom for our tests but this is not possible because of this issue. MSW is relying on this constructor (and I’m sure many other libraries do): https://github.com/mswjs/interceptors/blob/main/src/utils/getUrlByRequestOptions.ts#L91
It would be awesome if happy-dom could add this. 😃
We have now fixed this by using the native
url
module 🙂You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v7.8.0