test: use safe storage helpers in app mount hooks

This commit is contained in:
Peter Steinberger
2026-03-28 13:23:39 +00:00
parent 90e82fabb3
commit 5302aa8947
2 changed files with 17 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import { afterEach, beforeEach, vi } from "vitest";
import { i18n } from "../../i18n/index.ts";
import { getSafeLocalStorage, getSafeSessionStorage } from "../../local-storage.ts";
import "../app.ts";
import type { OpenClawApp } from "../app.ts";
@@ -32,8 +33,8 @@ export function mountApp(pathname: string) {
export function registerAppMountHooks() {
beforeEach(async () => {
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
localStorage.clear();
sessionStorage.clear();
getSafeLocalStorage()?.clear();
getSafeSessionStorage()?.clear();
document.body.innerHTML = "";
await i18n.setLocale("en");
vi.stubGlobal("WebSocket", MockWebSocket as unknown as typeof WebSocket);
@@ -45,8 +46,8 @@ export function registerAppMountHooks() {
afterEach(async () => {
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
localStorage.clear();
sessionStorage.clear();
getSafeLocalStorage()?.clear();
getSafeSessionStorage()?.clear();
document.body.innerHTML = "";
await i18n.setLocale("en");
vi.unstubAllGlobals();