import { sanitizeHtml, sanitizeSvg } from "./Sanitize"; // Mock the dynamic import for DOMPurify jest.mock("@/Core/DynamicImports", () => ({ dynamicImports: { dompurify: { get module() { // Return a mock DOMPurify object return Promise.resolve({ sanitize: (input: string, config?: any) => { // A simplified mock that mimics the real library for testing purposes. // It removes script tags and event handlers. if (typeof input !== "string") return ""; let sanitized = input.replace( /]*>[\s\S]*?<\/script>/gi, "" ); sanitized = sanitized.replace(/ on\w+="[^"]*"/gi, ""); // Remove on... event handlers // If svg profile is used, don't remove svg tags if (config?.USE_PROFILES?.svg) { return sanitized; } // Basic tag removal for non-SVG contexts if needed for a specific test // This mock is simple; the real library is much more complex. return sanitized; }, }); }, }, }, })); describe("Sanitization Functions", () => { describe("sanitizeHtml", () => { it("should remove script tags from HTML", async () => { const unsafeHtml = '

Hello World

'; const sanitized = await sanitizeHtml(unsafeHtml); expect(sanitized).not.toContain("'; const sanitized = await sanitizeSvg(unsafeSvg); expect(sanitized).not.toContain("