mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-04-18 22:35:42 +00:00
Add DOMPurify initialization in frontend test setup
- Integrated DOMPurify for sanitizing HTML in tests. - Added error handling for DOMPurify initialization to ensure robustness. - Made DOMPurify globally accessible in the test environment.
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
import { vi } from "vitest";
|
||||
import { config } from "@vue/test-utils";
|
||||
import createDOMPurify from "dompurify";
|
||||
|
||||
// Initialize DOMPurify with the jsdom window
|
||||
let DOMPurify;
|
||||
try {
|
||||
if (typeof createDOMPurify === "function") {
|
||||
DOMPurify = createDOMPurify(window);
|
||||
} else if (createDOMPurify && typeof createDOMPurify.default === "function") {
|
||||
DOMPurify = createDOMPurify.default(window);
|
||||
} else {
|
||||
DOMPurify = createDOMPurify;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to initialize DOMPurify:", e);
|
||||
}
|
||||
|
||||
// Global mocks
|
||||
if (DOMPurify) {
|
||||
global.DOMPurify = DOMPurify;
|
||||
window.DOMPurify = DOMPurify;
|
||||
}
|
||||
global.performance.mark = vi.fn();
|
||||
global.performance.measure = vi.fn();
|
||||
global.performance.getEntriesByName = vi.fn(() => []);
|
||||
|
||||
Reference in New Issue
Block a user