|
| 1 | +import { describe } from "vitest"; |
| 2 | +import { unescapeHTML } from "../../js/utils/unescapeHTMLentities"; |
| 3 | + |
| 4 | +describe("Unescape HTML entities function", () => { |
| 5 | + it("Single HTML entities decoded", () => { |
| 6 | + expect(unescapeHTML("&")).toBe("&"); |
| 7 | + expect(unescapeHTML("<")).toBe("<"); |
| 8 | + expect(unescapeHTML(">")).toBe(">"); |
| 9 | + expect(unescapeHTML(""")).toBe('"'); |
| 10 | + expect(unescapeHTML(""")).toBe('"'); |
| 11 | + expect(unescapeHTML("'")).toBe("'"); |
| 12 | + expect(unescapeHTML("/")).toBe("/"); |
| 13 | + expect(unescapeHTML("`")).toBe("`"); |
| 14 | + expect(unescapeHTML("=")).toBe("="); |
| 15 | + }); |
| 16 | + |
| 17 | + it("Multiple entities in a single string decoded", () => { |
| 18 | + const input = |
| 19 | + "<div class="test">Hello & Welcome/</div>"; |
| 20 | + const expected = '<div class="test">Hello & Welcome/</div>'; |
| 21 | + expect(unescapeHTML(input)).toBe(expected); |
| 22 | + }); |
| 23 | + |
| 24 | + it("String unchanged if no entities present", () => { |
| 25 | + const input = "Plain text with no HTML entities"; |
| 26 | + expect(unescapeHTML(input)).toBe(input); |
| 27 | + }); |
| 28 | + |
| 29 | + it("Empty string input handled", () => { |
| 30 | + expect(unescapeHTML("")).toBe(""); |
| 31 | + }); |
| 32 | + |
| 33 | + it("Non-string input converted to string", () => { |
| 34 | + expect(unescapeHTML(123 as any as string)).toBe("123"); |
| 35 | + expect(unescapeHTML(null as any)).toBe("null"); |
| 36 | + expect(unescapeHTML(undefined as any)).toBe("undefined"); |
| 37 | + expect(unescapeHTML(true as any)).toBe("true"); |
| 38 | + }); |
| 39 | +}); |
0 commit comments