Skip to content
File

Blob: tests/sites/island-hosts/island-host.test.tsx

typescript37 lines
1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it } from "vitest";
3 
4import { SiteIslandHost, serializeProps } from "@/sites/island-hosts/island-host";
5 
6describe("SiteIslandHost", () => {
7 it("emits an island host with template props and root", () => {
8 const html = renderToStaticMarkup(
9 <SiteIslandHost name="sites-image" props={{ src: "/_assets/1/x", align: "left" }}>
10 <span>body</span>
11 </SiteIslandHost>,
12 );
13 expect(html).toContain('data-island="sites-image"');
14 expect(html).toContain("<template");
15 expect(html).toContain("data-island-props");
16 expect(html).toContain("data-island-root");
17 expect(html).toContain("<span>body</span>");
18 });
19});
20 
21describe("serializeProps", () => {
22 it("escapes <, >, &, and line/paragraph separators", () => {
23 const text = serializeProps({ s: '</template><script>alert("x")</script>&\u2028\u2029' });
24 expect(text).not.toContain("</template>");
25 expect(text).not.toContain("<script");
26 expect(text).toContain("\\u003c");
27 expect(text).toContain("\\u003e");
28 expect(text).toContain("\\u0026");
29 expect(text).toContain("\\u2028");
30 expect(text).toContain("\\u2029");
31 });
32 
33 it("leaves other characters unchanged", () => {
34 expect(serializeProps({ s: "ok" })).toBe('{"s":"ok"}');
35 });
36});