Skip to content
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

Avoid { ...window.location } to support happy-dom #309

Open
anmolitor opened this issue Jan 9, 2025 · 1 comment
Open

Avoid { ...window.location } to support happy-dom #309

anmolitor opened this issue Jan 9, 2025 · 1 comment

Comments

@anmolitor
Copy link

In history.js there is a usage of { ...source.location }, which somehow works in the Browser,
but fails in other environments like happy-dom since the Browser behaviour around window.location
can only be emulated with get and set Methods.
Spreading does not take get Methods into account, so things like location.pathname will be undefined afterwards.

My suggestion is explicitely spreading the location, like so:

const getLocation = (source) => {
    return {
        pathname: source.location.pathname,
        href: source.location.href,
        origin: source.location.origin,
        ...
        state: source.history.state,
        key: (source.history.state && source.history.state.key) || "initial",
    };
};

What do you think? Or is there a good workaround for testing environments that I am unaware of?

@anmolitor
Copy link
Author

I also submitted an issue in happy-dom since I consider this a mismatch between the Browser DOM implementation and happy-dom, and it should be fixable on their side as well by adding artificial fields in the location class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant