Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

switch.test.tsx

20 lines804 Bytes

1import { renderToStaticMarkup } from "react-dom/server";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { Switch } from "./switch";
5​
6function renderSwitchRoot(props: Partial<Parameters<typeof Switch>[0]>) {
7 const html = renderToStaticMarkup(<Switch aria-label="Enable Claude Code" {...props} />);
8 return html.match(/<span[^>]*role="switch"[^>]*>/)?.[0] ?? "";
9}
10​
11describe("Switch accessibility", () => {
12 it("exposes the checked state to assistive tech", () => {
13 expect(renderSwitchRoot({ checked: true })).toContain('aria-checked="true"');
14 expect(renderSwitchRoot({ checked: false })).toContain('aria-checked="false"');
15 });
16​
17 it("exposes the mixed state", () => {
18 expect(renderSwitchRoot({ checked: false, mixed: true })).toContain('aria-checked="mixed"');
19 });
20});