From 7692533e18f1247bf7dbba9e0d3312a7b68401d8 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 26 Oct 2022 16:54:45 +0200 Subject: [PATCH] Improve fetch mock setup (#9511) - Move from language to mock setup file - Add mock rule for stub image requests --- test/setup/setupLanguage.ts | 4 ---- test/setup/setupManualMocks.ts | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/setup/setupLanguage.ts b/test/setup/setupLanguage.ts index 5efd8786cd..bd07616ab3 100644 --- a/test/setup/setupLanguage.ts +++ b/test/setup/setupLanguage.ts @@ -20,10 +20,6 @@ import * as languageHandler from "../../src/languageHandler"; import en from "../../src/i18n/strings/en_EN.json"; import de from "../../src/i18n/strings/de_DE.json"; -fetchMock.config.overwriteRoutes = false; -fetchMock.catch(""); -window.fetch = fetchMock.sandbox(); - const lv = { "Save": "Saglabāt", "Uploading %(filename)s and %(count)s others|one": "Качване на %(filename)s и %(count)s друг", diff --git a/test/setup/setupManualMocks.ts b/test/setup/setupManualMocks.ts index 31c716e375..2adda89e0f 100644 --- a/test/setup/setupManualMocks.ts +++ b/test/setup/setupManualMocks.ts @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import fetchMock from "fetch-mock-jest"; import { TextDecoder, TextEncoder } from "util"; // jest 27 removes setImmediate from jsdom @@ -54,3 +55,9 @@ global.TextDecoder = TextDecoder; // prevent errors whenever a component tries to manually scroll. window.HTMLElement.prototype.scrollIntoView = jest.fn(); + +// set up fetch API mock +fetchMock.config.overwriteRoutes = false; +fetchMock.catch(""); +fetchMock.get("/image-file-stub", "image file stub"); +window.fetch = fetchMock.sandbox();