Error: Not implemented: navigation

See original GitHub issue

After recent upgrade jest (which uses jsdom in background) from version 21.2.0 to 22.0.6 I have started getting error: "Error: Not implemented:" navigation

My code relies on window.location and I use in tests:

beforeEach(() => {
                window.location.href = `/ms/submission/?mybib`;
                window.location.search = '?mybib';
});

Is there a way to define a value of window.location.search using new version of jsdom?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:77
  • Comments:57 (7 by maintainers)

github_iconTop GitHub Comments

144reactions
hontascommented, Feb 5, 2018

Allow me to post the answer to my own question 😁 I simply replace the usages of window.location = url; and window.location.href = url; with

window.location.assign(url);

and then in my tests I did:

sinon.stub(window.location, 'assign');
expect(window.location.assign).to.have.been.calledWith(url);

Works like a charm - hope it can be of help to someone else šŸ‘

137reactions
chrisbatemancommented, Nov 26, 2018

If you don’t want to change your code to use location.assign - this seems to work with JSDom 11 and 13 (though there’s a chance JSDom might break it in the future…)

delete window.location;
window.location = {}; // or stub/spy etc.
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix Error: Not implemented: navigation (except hash ...
The reason JSDOM complains about the Error: Not implemented: navigation (except hash changes) is because JSDOM does not implement methods ...
Read more >
X" on Jest + JSDOM for component unit tests - Raul Melo
In this post I explain how to fix "Not implemented" problems while using Jest + JSDOM for component unit test.
Read more >
Jest error - Not implemented: navigation (except hash ...
Coding example for the question Jest error - Not implemented: navigation (except hash changes) when click event is triggered on an anchor element-Reactjs....
Read more >
Tip! Mock jsdom location with Jest - DEV Community ā€ ā€
You would receive an warning like below in case of jest running through above code: Error: Not implemented: navigation (except hash changes)Ā ...
Read more >
Assert window.location properties with Jest and jsdom - Notes
Error: Not implemented: navigation (except hash changes). That's fair enough! Adding navigation would be a big increase in scope for jsdom,Ā ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found