Skip to content

Commit

Permalink
Fix "Error: Not implemented: navigation (except hash changes)" during…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
bjoernricks committed Mar 28, 2024
1 parent 02a06a1 commit c1e3757
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@

import {initLocale} from 'gmp/locale/lang';

// Avoid "Error: Not implemented: navigation (except hash changes)"
// It is caused by clicking on <a> 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
Expand Down

0 comments on commit c1e3757

Please sign in to comment.