mirror of
https://github.com/vector-im/element-call.git
synced 2026-05-10 10:24:44 +00:00
Mock localStorage for testing in vitest setup (required as of Node.js v25.2.0)
This commit is contained in:
@@ -5,13 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import "global-jsdom/register";
|
||||
import "@formatjs/intl-durationformat/polyfill.js";
|
||||
import "@formatjs/intl-segmenter/polyfill";
|
||||
import i18n from "i18next";
|
||||
import posthog from "posthog-js";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
import { afterEach } from "vitest";
|
||||
import { afterEach, vi } from "vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import "vitest-axe/extend-expect";
|
||||
import { logger } from "matrix-js-sdk/lib/logger";
|
||||
@@ -20,6 +19,21 @@ import "@testing-library/jest-dom/vitest";
|
||||
import EN from "../locales/en/app.json";
|
||||
import { Config } from "./config/Config";
|
||||
|
||||
// Mock localStorage for tests
|
||||
const storage = new Map<string, string>();
|
||||
const localStorageMock = {
|
||||
getItem: vi.fn((key: string) => storage.get(key) || null),
|
||||
setItem: vi.fn((key: string, value: string) => storage.set(key, value)),
|
||||
removeItem: vi.fn((key: string) => storage.delete(key)),
|
||||
clear: vi.fn(() => storage.clear()),
|
||||
};
|
||||
|
||||
Object.defineProperty(globalThis, "localStorage", {
|
||||
value: localStorageMock,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
|
||||
// Bare-minimum i18n config
|
||||
i18n
|
||||
.use(initReactI18next)
|
||||
|
||||
Reference in New Issue
Block a user