Files
heroui-vue/tests/input-otp-ssr.test.ts
T

30 lines
981 B
TypeScript

// @vitest-environment node
import { expect, it } from "vitest";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import {
InputOTP,
InputOTPGroup,
InputOTPSlot,
Label,
} from "../packages/vue/src";
it("renders composed OTP names on the real native inputs without browser globals", async () => {
expect(typeof window).toBe("undefined");
const html = await renderToString(
createSSRApp({
render: () =>
h(InputOTP, { maxLength: 2, defaultValue: "12" }, () => [
h(Label, { id: "otp-server-label" }, () => "Security code"),
h(InputOTPGroup, {}, () => [
h(InputOTPSlot, { index: 0 }),
h(InputOTPSlot, { index: 1 }),
]),
]),
}),
);
expect(html.match(/aria-labelledby="otp-server-label"/g)).toHaveLength(2);
expect(html).toContain('value="1"');
expect(html).toContain('value="2"');
expect(html).not.toMatch(/aria-label="pin input/);
});