test: replace ui prototype method patches with instance stubs

This commit is contained in:
Peter Steinberger
2026-02-17 01:57:42 +01:00
parent c20ef582cb
commit dcdbbd8b3b
3 changed files with 8 additions and 31 deletions

View File

@@ -1,15 +1,11 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { OpenClawApp } from "./app.ts";
import { describe, expect, it } from "vitest";
import "../styles.css";
import { mountApp as mountTestApp, registerAppMountHooks } from "./test-helpers/app-mount.ts";
// oxlint-disable-next-line typescript/unbound-method
const originalConnect = OpenClawApp.prototype.connect;
registerAppMountHooks();
function mountApp(pathname: string) {
window.history.replaceState({}, "", pathname);
const app = document.createElement("openclaw-app") as OpenClawApp;
document.body.append(app);
return app;
return mountTestApp(pathname);
}
function nextFrame() {
@@ -18,22 +14,6 @@ function nextFrame() {
});
}
beforeEach(() => {
OpenClawApp.prototype.connect = () => {
// no-op: avoid real gateway WS connections in browser tests
};
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
localStorage.clear();
document.body.innerHTML = "";
});
afterEach(() => {
OpenClawApp.prototype.connect = originalConnect;
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
localStorage.clear();
document.body.innerHTML = "";
});
describe("control UI routing", () => {
it("hydrates the tab from the location", async () => {
const app = mountApp("/sessions");

View File

@@ -1,28 +1,24 @@
import { afterEach, beforeEach } from "vitest";
import { OpenClawApp } from "../app.ts";
// oxlint-disable-next-line typescript/unbound-method
const originalConnect = OpenClawApp.prototype.connect;
export function mountApp(pathname: string) {
window.history.replaceState({}, "", pathname);
const app = document.createElement("openclaw-app") as OpenClawApp;
app.connect = () => {
// no-op: avoid real gateway WS connections in browser tests
};
document.body.append(app);
return app;
}
export function registerAppMountHooks() {
beforeEach(() => {
OpenClawApp.prototype.connect = () => {
// no-op: avoid real gateway WS connections in browser tests
};
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
localStorage.clear();
document.body.innerHTML = "";
});
afterEach(() => {
OpenClawApp.prototype.connect = originalConnect;
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
localStorage.clear();
document.body.innerHTML = "";