From 816ae4d9f4cde3ebfa63ec677ef39b1c4d516a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Mon, 8 Apr 2024 15:59:43 +0100 Subject: [PATCH] web: Fix tests - Add missing mock. --- web/src/components/core/Page.test.jsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/web/src/components/core/Page.test.jsx b/web/src/components/core/Page.test.jsx index 36949c1a1c..5db0ec6349 100644 --- a/web/src/components/core/Page.test.jsx +++ b/web/src/components/core/Page.test.jsx @@ -1,5 +1,5 @@ /* - * Copyright (c) [2023] SUSE LLC + * Copyright (c) [2023-2024] SUSE LLC * * All Rights Reserved. * @@ -23,12 +23,35 @@ import React from "react"; import { screen, within } from "@testing-library/react"; import { installerRender, plainRender, mockNavigateFn } from "~/test-utils"; import { Page } from "~/components/core"; +import { createClient } from "~/client"; + +jest.mock("~/client"); + +const l10nClientMock = { + getUILocale: jest.fn().mockResolvedValue("en_US"), + keymaps: jest.fn().mockResolvedValue([]), + getKeymap: jest.fn().mockResolvedValue(undefined), + timezones: jest.fn().mockResolvedValue([]), + getTimezone: jest.fn().mockResolvedValue(undefined), + onLocalesChange: jest.fn(), + onKeymapChange: jest.fn(), + onTimezoneChange: jest.fn() +}; describe("Page", () => { beforeAll(() => { jest.spyOn(console, "error").mockImplementation(); }); + beforeEach(() => { + // if defined outside, the mock is cleared automatically + createClient.mockImplementation(() => { + return { + l10n: l10nClientMock + }; + }); + }); + afterAll(() => { console.error.mockRestore(); });