Skip to content

Difference in behaviour when spreading location object #1682

Open
@anmolitor

Description

Describe the bug

When executing { ...window.location } in the browser, you get back an object containing all the usual properties like
{ href: ..., origin: ..., pathname: ..., search: ..., hash: ... } etc.
In happy-dom, this does not work, since the spread operator only considers non-private fields and the Location class currently stores a private URL instead.

To Reproduce
Steps to reproduce the behavior:

  1. Execute { ...window.location } in the dev tools of this tab
  2. Execute a happy-dom test and log { ...window.location } out
  3. See a noticable difference

Expected behavior
The outcome is the same (object with all properties of window.location)

Device:

  • any

Additional context
I suggest fixing this bug by adding non-private (they may be typescript-private but not #) fields to the location class,
which mirror the fields in the private URL field. When URL is set, also set all related fields.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions