Skip to content

Instantly share code, notes, and snippets.

@hongkheng
Created April 30, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongkheng/ec3ed42ba7b7f70f909f1b456f1b2314 to your computer and use it in GitHub Desktop.
Save hongkheng/ec3ed42ba7b7f70f909f1b456f1b2314 to your computer and use it in GitHub Desktop.
Jest/jsdom navigation errors

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment