@cxl/spec
v1.1.0
Published
This library provides a comprehensive testing framework tailored for browser environments, offering utilities for defining tests, assertions, DOM manipulations, event handling, mocking, spying, and accessibility checks.
Downloads
68
Readme
@cxl/spec
This library provides a comprehensive testing framework tailored for browser environments, offering utilities for defining tests, assertions, DOM manipulations, event handling, mocking, spying, and accessibility checks.
Project Details
Installation
npm install @cxl/specFeatures
- Define synchronous and asynchronous tests and test suites with
TestandTestApi. - Assertions for equality, partial matching, buffer comparison, throwing errors, and custom assertions.
- DOM manipulation helpers and connected test DOM containers.
- Event expectation and testing utilities with promise-based APIs.
- Mocking and spying of functions and properties.
- Accessibility testing integration.
- Advanced time mocking for
setTimeout,setInterval, andrequestAnimationFrame. - Actions like hover, tap, click, type, and press with runner command integration.
- Figure-based visual testing support.
- Calibrated synchronous and asynchronous browser benchmarks.
- Structured JSON result output for tests.
Defining Tests
import { spec } from '@cxl/spec';
spec('Example test', async test => {
test.ok(true, 'This test should pass');
test.equal(1 + 1, 2, 'Math works');
await test.testElement('test a DOM element', async a => {
const el = a.element('div');
a.ok(el instanceof HTMLElement, 'Element created');
});
});Benchmarks
Benchmark identity comes from the enclosing test path. The callback is repeated during warmup and sampling, so it must be safe to run multiple times.
import { spec } from '@cxl/spec';
export default spec('compiler benchmarks', s => {
s.test('compile module', a =>
a.benchmark(() => compile(source)),
);
});Projects using @cxl/build place benchmarks in test-benchmark.ts and run them
with npm run build benchmark.
