To resolve errors from jest test such as:
Error: Not implemented: navigation (except hash changes)
at module.exports (/Users/pyhk329d/workspace/sppower-projects/lighthouse-web/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
at navigateFetch (/Users/pyhk329d/workspace/sppower-projects/lighthouse-web/node_modules/jsdom/lib/jsdom/living/window/navigation.js:77:3)
at exports.navigate (/Users/pyhk329d/workspace/sppower-projects/lighthouse-web/node_modules/jsdom/lib/jsdom/living/window/navigation.js:55:3)
at Timeout._onTimeout (/Users/pyhk329d/workspace/sppower-projects/lighthouse-web/node_modules/jsdom/lib/jsdom/living/nodes/HTMLHyperlinkElementUtils-impl.js:81:7)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) undefined
at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
at module.exports (node_modules/jsdom/lib/jsdom/browser/not-implemented.js:12:26)
at navigateFetch (node_modules/jsdom/lib/jsdom/living/window/navigation.js:77:3)
at exports.navigate (node_modules/jsdom/lib/jsdom/living/window/navigation.js:55:3)
at Timeout._onTimeout (node_modules/jsdom/lib/jsdom/living/nodes/HTMLHyperlinkElementUtils-impl.js:81:7)
If the unit test is testing for link e.g. <a href="link"></a>
. Mocking window.location
will not work. Reconfiguring the jsdom
in Jest with a custom one works. Can use this package https://github.com/simon360/jest-environment-jsdom-global
to expose the global jsdom and reconfigure url
property to make the error go away.