test(sanitizer): add tests for cozify()
This commit is contained in:
parent
ace0f6a4bf
commit
d5b373df48
1 changed files with 31 additions and 0 deletions
31
src/utils/sanitizer.test.ts
Normal file
31
src/utils/sanitizer.test.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { describe, expect, test } from "vitest";
|
||||
import { cozify } from "./sanitizer";
|
||||
|
||||
describe("cozify()", async () => {
|
||||
const baseUrl = "https://cozy.pub";
|
||||
|
||||
test("should remove scripts", async () => {
|
||||
const html = "<h1>HELLO</h1><script>console.log()</script>";
|
||||
const result = await cozify(html, baseUrl);
|
||||
expect(result).not.toContain("<script>");
|
||||
});
|
||||
|
||||
test("should remove target=_blank from links", async () => {
|
||||
const html = "<a href=# target='_blank'>hey</a>";
|
||||
const result = await cozify(html, baseUrl);
|
||||
expect(result).not.toContain("target");
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
test("should add base url to href of links", async () => {
|
||||
const html = "<a href=#>hey</a>";
|
||||
const result = await cozify(html, baseUrl);
|
||||
expect(result).toContain('href="https://cozy.pub?url=#"');
|
||||
});
|
||||
|
||||
test("should add prefetch=true of links", async () => {
|
||||
const html = "<a href=#>hey</a>";
|
||||
const result = await cozify(html, baseUrl);
|
||||
expect(result).toContain('prefetch="true"');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue