PettyUI/packages/core/tests/button.test.ts
Mats Bosson bf576905a7
Some checks are pending
CI / check (push) Waiting to run
All components, schemas, tests, MCP, and showcase
- 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
2026-03-31 20:21:41 +07:00

44 lines
1.3 KiB
TypeScript

import { describe, it, expect, beforeEach } from "vitest";
import "../src/components/button/index";
import { h } from "./helpers";
describe("petty-button", () => {
let el: HTMLElement;
beforeEach(() => {
document.body.textContent = "";
el = document.createElement("petty-button");
el.appendChild(h("button", {}, "Click"));
document.body.appendChild(el);
});
it("registers the custom element", () => {
expect(customElements.get("petty-button")).toBeDefined();
});
it("syncs disabled state to child button", () => {
el.setAttribute("disabled", "");
const btn = el.querySelector("button")!;
expect(btn.disabled).toBe(true);
expect(btn.getAttribute("aria-disabled")).toBe("true");
expect(el.dataset.state).toBe("disabled");
});
it("syncs loading state to child button", () => {
el.setAttribute("loading", "");
const btn = el.querySelector("button")!;
expect(btn.disabled).toBe(true);
expect(btn.getAttribute("aria-busy")).toBe("true");
expect(el.dataset.state).toBe("loading");
});
it("clears loading and disabled state", () => {
el.setAttribute("loading", "");
el.removeAttribute("loading");
const btn = el.querySelector("button")!;
expect(btn.disabled).toBe(false);
expect(btn.getAttribute("aria-busy")).toBeNull();
expect(el.dataset.state).toBe("idle");
});
});