Skip to content

Manipulation with window location is no longer possible #3492

Description

@avlapeto

Basic info:

  • Node.js version: 18.12.0
  • jsdom version: 21.0.0

Minimal reproduction case

We have a page that performs a redirect to an external page based on query string parameters:

...
<script>
const redirectUrl = 'https://github.com/'
window.location.href = redirectUrl;
// window.location.assign(redirectUrl);
</script>
...

and integration test that expects that location.href will be changed (or location.assing will be invoked with some params).

    const windowLocation = {};
    const { window } = new JSDOM(response.text, {
      beforeParse(window) {
        delete window.location;
        window.location = windowLocation;
      },
      runScripts: 'dangerously',
    });
   expect(windowLocation.href).toBe('https://github.com/');

Previously (jsdom 20.0.3) we changed the original location object to a syntetic one and ran an expectation on it. But since window.location became non-configurable, it's no longer possible. 
Any advice about options to spy on location object?

Right now, we are getting:

Error: Not implemented: navigation (except hash changes).

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions