Skip to content
assay logoAssayTesting
Scoped DOM queries, exact event dispatch, and cancellable async waiting for browser tests.
Version
v2.1.0
Size
1.5 KB gzip
Dependencies
Zero dependencies
Browser
withinqueryInShadowqueryAllInShadowqueryPartgetSlotted View all 23 exports

Why Assay?

Assay provides focused DOM test primitives that work with vanilla elements, custom elements, and framework-rendered output. It scopes queries, dispatches exact browser event classes, and waits on explicit conditions without imposing a renderer or browser automation stack.

ts
// Before
button.dispatchEvent(new MouseEvent('click', { bubbles: true }));
await new Promise((resolve) => setTimeout(resolve, 100));

// After
fireClick(view.get('button.submit'));
await waitUntil(() => view.queryByText('Saved') !== null);
FeatureAssayTesting Library DOMBrowser automation
Bundle size1.5 KBLarger query layerBrowser runtime required
Zero dependencies
Scoped DOM querieswithin() and shadow helpersRenderer-oriented queriesManual selectors
Deterministic waitswaitUntil() and waitForEvent()Framework-dependentFull browser timing

Use Assay when a DOM unit test needs readable queries, dispatched events, or a bounded async wait without adopting a rendering framework.

Consider browser integration tests when correctness depends on browser default actions, focus behavior, pointer capture, layout, or accessibility-tree behavior.

Installation

sh
pnpm add -D @vielzeug/assay
sh
npm install -D @vielzeug/assay
sh
yarn add -D @vielzeug/assay

Quick Start

Scope a test fixture, dispatch an event, and wait for resulting DOM state.

ts
import { fireClick, waitUntil, within } from '@vielzeug/assay';

const panel = document.createElement('section');
panel.innerHTML = '<button>Save</button><output></output>';
panel.querySelector('button')!.addEventListener('click', () => {
  panel.querySelector('output')!.textContent = 'Saved';
});

const view = within(panel);
fireClick(view.get('button'));
await waitUntil(() => view.queryByText('Saved') !== null);

Features

  • within(root) scopes nullable and required DOM queries.
  • queryInShadow, queryPart, and getSlotted cross custom-element boundaries explicitly.
  • fireClick, fireInput, fireKeyDown, and peers dispatch exact synchronous events.
  • waitUntil, retry, and waitForEvent provide bounded, abortable async waiting.
  • delay and nextTick model explicit timer and microtask scheduling.
  • AssayError, AssayQueryError, and AssayTimeoutError provide typed failures.

Documentation

See Also

  • Ore — component authoring and test fixtures that pair with Assay DOM helpers.
  • Refine — accessible components with component-specific test assertions.