{"id":665,"hash":"58a7d73f1f8551ebbb7a20fc0c3e9c75bd4d97c76fcd55a2d1a28e7839dbb9a6","pattern":"How to fix Error: Not implemented: navigation (except hash changes)","full_message":"I am implementing unit test for a file that contain window.location.href and I need to check it.\n\nMy jest version is 22.0.4. Everything is fine when I run my test on node version >=10\n\nBut I get this error when I run it on v8.9.3\n\nconsole.error node_modules/jsdom/lib/jsdom/virtual-console.js:29\n      Error: Not implemented: navigation (except hash changes)\n\nI have no idea about it. I have searched on many page to find out the solution or any hint about this to figure out what happened here.\n\n[UPDATE] - I took a look deep to source code and I think this error is from jsdom.\n\nat module.exports (webapp/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)\nat navigateFetch (webapp/node_modules/jsdom/lib/jsdom/living/window/navigation.js:74:3)\n\nnavigation.js file\n\nexports.evaluateJavaScriptURL = (window, urlRecord) => {\n  const urlString = whatwgURL.serializeURL(urlRecord);\n  const scriptSource = whatwgURL.percentDecode(Buffer.from(urlString)).toString();\n  if (window._runScripts === \"dangerously\") {\n    try {\n      return window.eval(scriptSource);\n    } catch (e) {\n      reportException(window, e, urlString);\n    }\n  }\n  return undefined;\n};\nexports.navigate = (window, newURL, flags) => {\n  // This is NOT a spec-compliant implementation of navigation in any way. It implements a few selective steps that\n  // are nice for jsdom users, regarding hash changes and JavaScript URLs. Full navigation support is being worked on\n  // and will likely require some additional hooks to be implemented.\n\n  const document = idlUtils.implForWrapper(window._document);\n  const currentURL = document._URL;\n\n  if (!flags.reloadTriggered && urlEquals(currentURL, newURL, { excludeFragments: true })) {\n    if (newURL.fragment !== currentURL.fragment) {\n      navigateToFragment(window, newURL, flags);\n    }\n    return;\n  }\n\n  // NOT IMPLEMENTED: Prompt to unload the active document of browsingContext.\n\n  // NOT IMPLEMENTED: form submission algorithm\n  // const navigationType = 'other';\n\n  // NOT IMPLEMENTED: if resource is a response...\n  if (newURL.scheme === \"javascript\") {\n    window.setTimeout(() => {\n      const result = exports.evaluateJavaScriptURL(window, newURL);\n      if (typeof result === \"string\") {\n        notImplemented(\"string results from 'javascript:' URLs\", window);\n      }\n    }, 0);\n    return;\n  }\n  navigateFetch(window);\n};\n\nnot-implemented.js\n\nmodule.exports = function (nameForErrorMessage, window) {\n  if (!window) {\n    // Do nothing for window-less documents.\n    return;\n  }\n\n  const error = new Error(`Not implemented: ${nameForErrorMessage}`);\n  error.type = \"not implemented\";\n\n  window._virtualConsole.emit(\"jsdomError\", error);\n};\n\nI see some weird logics in these file.\n\nconst scriptSource = whatwgURL.percentDecode(Buffer.from(urlString)).toString();\nthen check string and return error","ecosystem":"npm","package_name":"unit-testing","package_version":null,"solution":"I faced a similar issue in one of my unit tests. Here's what I did to resolve it.\n\nReplace window.location.href with window.location.assign(url) OR\nwindow.location.replace(url)\n\nJSDOM will still complain about window.location.assign not implemented.\n\n Error: Not implemented: navigation (except hash changes)\n\nThen, in one of your unit tests for the above component / function containing window.assign(url) or window.replace(url) define the following\n\nsinon.stub(window.location, 'assign');\n\nsinon.stub(window.location,   'replace');\n\nMake sure you import sinon import sinon from 'sinon';\n\n Hopefully, this should fix the issue for you as it did for me.\n\nThe reason JSDOM complains about the ` Error: Not implemented: navigation (except hash changes)` is because JSDOM does not implement methods like `window.alert`, `window.location.assign`, etc.\n\nReferences:\n\nhttps://www.npmjs.com/package/jsdom#virtual-consoles\nhttps://www.npmjs.com/package/jsdom#unimplemented-parts-of-the-web-platform","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/54090231/how-to-fix-error-not-implemented-navigation-except-hash-changes","votes":122,"created_at":"2026-04-19T04:51:27.268342+00:00","updated_at":"2026-04-19T04:51:27.268342+00:00"}