| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | import { renderToStaticMarkup } from "react-dom/server"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { Switch } from "./switch"; |
| 5 | |
| 6 | function 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 | |
| 11 | describe("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 | }); |