Some checks are pending
CI / check (push) Waiting to run
- 51 headless Web Components (45 core + 6 animation) - Shared helpers: emit(), part(), listen(), wireLabel(), initialValue() - Zero `new CustomEvent` or `static #counter` — all use shared utils - Zod schemas for all 44 core components - MCP package with discover, inspect, compose, validate tools - Showcase with Aperture Science theme, M3 Expressive motion - 81 tests passing, TypeScript strict mode clean - Signals (~500B), SPA router (~400B), zero dependencies
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { PettyCheckbox } from "../src/components/checkbox/index";
|
|
import { h } from "./helpers";
|
|
|
|
describe("petty-checkbox", () => {
|
|
let el: PettyCheckbox;
|
|
|
|
beforeEach(() => {
|
|
document.body.textContent = "";
|
|
el = document.createElement("petty-checkbox") as PettyCheckbox;
|
|
const input = h("input", { type: "checkbox", "data-part": "control" });
|
|
const label = h("label", { "data-part": "label" }, "Accept");
|
|
el.appendChild(input);
|
|
el.appendChild(label);
|
|
document.body.appendChild(el);
|
|
});
|
|
|
|
it("registers the custom element", () => {
|
|
expect(customElements.get("petty-checkbox")).toBe(PettyCheckbox);
|
|
});
|
|
|
|
it("defaults to unchecked state", () => {
|
|
expect(el.checked).toBe(false);
|
|
expect(el.dataset.state).toBe("unchecked");
|
|
});
|
|
|
|
it("sets checked state via property", () => {
|
|
el.checked = true;
|
|
const input = el.querySelector("input") as HTMLInputElement;
|
|
expect(input.checked).toBe(true);
|
|
expect(el.dataset.state).toBe("checked");
|
|
});
|
|
|
|
it("sets indeterminate state", () => {
|
|
el.indeterminate = true;
|
|
const input = el.querySelector("input") as HTMLInputElement;
|
|
expect(input.indeterminate).toBe(true);
|
|
expect(el.dataset.state).toBe("indeterminate");
|
|
});
|
|
|
|
it("wires label htmlFor to input id", () => {
|
|
const input = el.querySelector("input") as HTMLInputElement;
|
|
const label = el.querySelector("label") as HTMLLabelElement;
|
|
expect(input.id).not.toBe("");
|
|
expect(label.htmlFor).toBe(input.id);
|
|
});
|
|
});
|