mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 05:15:59 +01:00
refactor(test): global initialisation
This commit is contained in:
51
src/public/app/test-setup.ts
Normal file
51
src/public/app/test-setup.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { beforeAll, vi } from "vitest";
|
||||
import $ from "jquery";
|
||||
|
||||
beforeAll(() => {
|
||||
injectGlobals();
|
||||
vi.mock("./services/ws.js", mockWebsocket);
|
||||
vi.mock("./services/server.js", mockServer);
|
||||
});
|
||||
|
||||
function injectGlobals() {
|
||||
const uncheckedWindow = window as any;
|
||||
uncheckedWindow.$ = $;
|
||||
uncheckedWindow.WebSocket = () => {};
|
||||
uncheckedWindow.glob = {
|
||||
isMainWindow: true
|
||||
};
|
||||
}
|
||||
|
||||
function mockWebsocket() {
|
||||
return {
|
||||
default: {
|
||||
subscribeToMessages(callback: (message: unknown) => void) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mockServer() {
|
||||
return {
|
||||
default: {
|
||||
async get(url: string) {
|
||||
if (url === "options") {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (url === "keyboard-actions") {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (url === "tree") {
|
||||
return {
|
||||
branches: [],
|
||||
notes: [],
|
||||
attributes: []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user