@azerothjs/testing
v2.1.0
Published
AzerothJS testing utilities - auto-disposing mounts, subscriber leak guards, event helpers
Downloads
468
Maintainers
Readme
@azerothjs/testing
AzerothJS testing utilities - auto-disposing mounts, subscriber leak guards, event helpers
Part of AzerothJS - the fine-grained fullstack framework. Test helpers for azerothjs apps: auto-disposing mounts, subscriber leak guards, and a bubbling-event helper. Install as a dev dependency alongside the framework.
import { renderTest, leakGuard, fire, cleanup } from '@azerothjs/testing';
import { createSignal, h } from 'azerothjs';
it('updates and tears down cleanly', () =>
{
const [count, setCount] = createSignal(0);
const check = leakGuard(count);
const { container, unmount } = renderTest(() =>
h('p', {}, () => `count: ${ count() }`));
expect(container.textContent).toBe('count: 0');
setCount(1);
expect(container.textContent).toBe('count: 1');
unmount();
check(); // throws if any subscription survived the unmount
});renderTest(component)mounts into a fresh container indocument.body(attached, so delegated events from compileddom-target code fire) and returns{ container, unmount }.cleanup()unmounts everything still mounted. With a test runner whose globals are enabled (vitestglobals: true, jest) it registers itself inafterEachautomatically at import time; otherwise call it from your ownafterEach.leakGuard(...getters)snapshots subscriber counts and returns an assertion that throws if teardown left subscriptions behind.fire(el, type, init?)dispatches a bubbling, cancelable event.
Install
[!NOTE] ESM-only, Node >= 22.
azerothjsis a required peer - the helpers mount and inspect its reactive trees:
npm install -D @azerothjs/testing azerothjsRelated
- AzerothJS - the monorepo overview and the full package list.
azerothjs- the framework runtime these helpers mount and inspect (required peer).@azerothjs/kit- per-route SSR, prerendering, and hydration for fullstack apps.
