From c602bc2b42fa9fad4a2837deed4b51e163666795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 28 Mar 2024 13:29:07 +0100 Subject: [PATCH] Fix "Error: Not implemented: navigation (except hash changes)" during tests JSDOM doesn't implement the navigation API and therefore raises an error in the console if `window.location` is used and anchors are clicked. As we are using a lot of anchors in our pages this error is raised often during test runs. By mocking the HTMLAnchorElement click handler the console error is silenced. --- src/setupTests.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/setupTests.js b/src/setupTests.js index c8ef810901..c5845b2861 100644 --- a/src/setupTests.js +++ b/src/setupTests.js @@ -18,10 +18,15 @@ import {initLocale} from 'gmp/locale/lang'; +// Avoid "Error: Not implemented: navigation (except hash changes)" +// It is caused by clicking on elements in tests +// https://stackoverflow.com/a/68038982/11044073 +HTMLAnchorElement.prototype.click = jest.fn(); + class FakeBackend { read(language, namespace, callback) { if (language.startsWith('en') || language.startsWith('de')) { - // change language by calling the callback functioon + // change language by calling the callback function return callback(); } // change language and pass error message