-
-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#678@patch: Assign of window.location.href. #685
#678@patch: Assign of window.location.href. #685
Conversation
|
||
describe('href', () => { | ||
it('Set href.', () => { | ||
location.replace(HREF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test against a plain string like /Foo instead of using a valid url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you means location.href = '/foo'
directly, like this:
const {Window} = require('happy-dom');
const window = new Window();
window.location.href = '/foo'
or
const {Window} = require('happy-dom');
const window = new Window();
window.location.href = ''
window.location.href = '/foo'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. I'm watching this from my phone but it seems that HREF is a complete and valid url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. I'm watching this from my phone but it seems that HREF is a complete and valid url.
we need have a valid url before we location.href = '/foo'
, it's same in browser. /foo
only a path, it's not valid url. you can set href /foo
because it's replace pathname only.
you can test in your browser devtools:
location.href = 'about:blank' // the blank page in browser.
location.href = '/foo'
// Uncaught DOMException: Failed to set the 'href' property on 'Location': '/foo' is not a valid URL.
// at <anonymous>:1:15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilteoood as @Mas0nShi said, the URL needs to be relative to something and by default the URL is set to "about:blank".
Only setting location.href = '/foo'
will fail with an error as it is not possible to construct a relative URL from "about:blank". Happy DOM could use a different default value for the URL, but what would that be?
After this fix, you will still have to use a setup script for your tests and set a default URL for the URL:s to be relative from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added unit tests that demonstrates this.
I hate to be that guy, but any update on this? It's currently blocking me from using happy-dom instead of jsdom |
@hugo-vrijswijk the build for this PR is failing and I would also like to look into the solution a bit more. I am currently working on #677, which adds support for FormData and implements "fetch" into Happy DOM. It is a bit time consuming. I will look into this as soon as I can 😅 |
…78-fixes-window-location-href
Fixes #678.