commit 5de299e258fecb2893b44bca28ab0f1052e23c90
parent 483d6da704e644f3f4fc741dd7cbd34b4a2423a2
Author: ms <ms@taler.net>
Date: Sat, 8 Jan 2022 11:03:56 +0100
mocking local storage in tests
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/packages/bank/build-bank-translations.sh b/packages/bank/build-bank-translations.sh
@@ -2,6 +2,9 @@
set -eu
+# NOTE: the <Translate> node somehow didn't get
+# the strings extracted. Only i18n`` did
+
function build {
POTGEN=node_modules/@gnu-taler/pogen/bin/pogen
PACKAGE_NAME=$1
diff --git a/packages/bank/tests/__tests__/homepage.js b/packages/bank/tests/__tests__/homepage.js
@@ -7,6 +7,14 @@ import { waitFor, cleanup, render, fireEvent, screen } from '@testing-library/pr
import expect from 'expect';
import fetchMock from "jest-fetch-mock";
+/**
+ * This mock makes the translator always return the
+ * english string. It didn't work within the 'beforeAll'
+ * function...
+ */
+jest.mock("../../src/i18n")
+const i18n = require("../../src/i18n")
+i18n.useTranslator.mockImplementation(() => function(arg) {return arg})
beforeAll(() => {
Object.defineProperty(window, 'location', {
@@ -15,6 +23,10 @@ beforeAll(() => {
pathname: "/demobanks/default"
}
})
+ // Invalidating local storage: makes it more difficult
+ // to isolate the individual tests, and it doesn't really
+ // participate in the SPA logic.
+ global.Storage.prototype.setItem = jest.fn((key, value) => {})
})
/**