Testing Guidelines
The Elements library uses a comprehensive testing strategy with many test types to ensure quality, accessibility, and performance. All tests follow consistent patterns and use shared utilities from @internals/testing and @internals/vite.
Running Tests
Run test scripts from the root directory of the project where the package.json lives.
# Unit tests
pnpm run test
# Single test suite
pnpm run test -- src/badge/badge.test.ts
# Accessibility tests
pnpm run test:axe
# Performance tests
pnpm run test:lighthouse
# Visual regression tests
pnpm run test:visual
# SSR tests
pnpm run test:ssr
Test Types
Unit Tests (.test.ts)
- Unit Tests (
.test.ts): Standard behavior tests. - Accessibility Tests (
.test.axe.ts): best practices tests using axe-core. - Lighthouse Performance Tests (
.test.lighthouse.ts): performance audits and best practices via Lighthouse - Visual Regression Tests (
.test.visual.ts): Visual regression tests using Playwright screenshots. - SSR Tests (
.test.ssr.ts): Server-side rendering compatibility tests.
Test Configuration
Vitest Configs
Each test type has its own Vitest configuration:
- Unit tests:
vitest.config.tsusinglibraryTestConfig - Axe tests:
vitest.axe.tsusinglibraryAxeTestConfig - Lighthouse tests:
vitest.lighthouse.tsusinglibraryLighthouseConfig - Visual tests:
vitest.visual.tsusinglibraryVisualTestConfig - SSR tests:
vitest.ssr.tsusinglibraryLitSSRTestConfig
HTML Templates
Lighthouse and Visual tests require HTML templates:
vitest.lighthouse.html- Base template for Lighthouse testsvitest.visual.html- Base template for Visual tests
Testing Utilities
@internals/testing
Core testing utilities for DOM manipulation and element stability:
createFixture: Creates test fixture DOM elementremoveFixture: Removes test fixture DOMelementIsStable: Waits for Lit element to be stableemulateClick: Triggers native click eventsuntilEvent: Creates promise for event results