Files
heroui-vue/tests/ssr.test.ts
T
2026-10-21 13:04:06 +08:00

39 lines
1.1 KiB
TypeScript

// @vitest-environment node
import { it, expect } from "vitest";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import {
Button,
Card,
Input,
Switch,
Surface,
Link,
LinkIcon,
Spinner,
TextArea,
} from "../packages/vue/src";
it("renders the initial components without browser globals", async () => {
const html = await renderToString(
createSSRApp({
render: () =>
h(Card, () => [
h(Button, () => "保存"),
h(Input, { modelValue: "名称" }),
h(Switch, { checked: true, "aria-label": "通知" }),
h(Surface, { variant: "secondary" }, () => h("span", "表面")),
h(Link, { href: "#" }, () => ["链接", h(LinkIcon)]),
h(Spinner),
h(TextArea, { modelValue: "备注" }),
]),
}),
);
expect(html).toContain("保存");
expect(html).toContain('value="名称"');
expect(html).toContain('role="switch"');
expect(html).toContain("hv-surface--secondary");
expect(html).toContain('data-slot="link"');
expect(html).toContain('role="status"');
expect(html).toContain('data-slot="textarea"');
});