Open History to see the last commit
1import type { Root } from "hast";
2import { renderToStaticMarkup } from "react-dom/server";
3import { createElement, Fragment } from "react";
4import { describe, expect, it } from "vite-plus/test";
5
6import { renderHastWithIslands } from "./markdownIslands";
7
8describe("renderHastWithIslands", () => {
9 it("writes SVG attributes by their SVG names in static HTML", () => {
10 const tree: Root = {
11 type: "root",
12 children: [
13 {
14 type: "element",
15 tagName: "p",
16 properties: {},
17 children: [
18 {
19 type: "element",
20 tagName: "svg",
21 properties: { viewBox: "0 0 1 1" },
22 children: [
23 {
24 type: "element",
25 tagName: "text",
26 properties: { fontSize: "700", strokeWidth: "2" },
27 children: [{ type: "text", value: "x" }],
28 },
29 ],
30 },
31 ],
32 },
33 ],
34 };
35 const html = renderToStaticMarkup(
36 createElement(
37 Fragment,
38 null,
39 renderHastWithIslands(tree, {
40 components: {},
41 variant: "",
42 isIsland: () => false,
43 staticElement: (node) => node,
44 }),
45 ),
46 );
47 expect(html).toContain('<text font-size="700" stroke-width="2">x</text>');
48 expect(html).toContain('viewBox="0 0 1 1"');
49 });
50});