@triggery/testing
Testing utilities for Triggery. Zero runtime dependencies, framework-agnostic — works the same in React, Solid, Vue tests, Node, or a worker; compatible with Vitest, Jest, and node:test.
The same trigger code you ship runs in tests without React, JSDOM, or a host framework. You test scenarios, not components.
Install
Section titled “Install”pnpm add -D @triggery/core @triggery/testing npm install --save-dev @triggery/core @triggery/testing yarn add --save-dev @triggery/core @triggery/testing bun add -D @triggery/core @triggery/testing Peer deps: @triggery/core. Test-runner agnostic — no dependency on vi.useFakeTimers() / jest.useFakeTimers().
What’s inside
Section titled “What’s inside”| Export | Purpose |
|---|---|
createTestRuntime({ triggers? }) | Isolated runtime per test. No global state pollution. |
mockCondition(trigger, name, value | getter) | Supply a condition without rendering a component. |
mockAction(trigger, name, fn) | Register an action handler — typically vi.fn() / jest.fn(). |
flushMicrotasks() | Drain the default microtask scheduler before asserting. |
createFakeScheduler() | Controllable virtual clock for actions.debounce / throttle / defer. |
createFakeScheduler() exposes:
install()/uninstall()swapglobalThis.setTimeout/clearTimeoutfor a controlled implementation.advance(ms)runs every timer due within the window and drains microtasks.flushAll()runs every pending timer regardless of scheduled time.
Quick example
Section titled “Quick example”A trigger that gates on a user.isMod condition and fires two actions:
No DOM, no provider, no act(). The trigger is exercised directly.
Fake scheduler — testing debounce
Section titled “Fake scheduler — testing debounce”Async handlers — take-latest
Section titled “Async handlers — take-latest”Related packages
Section titled “Related packages” @triggery/core Same runtime, just instantiated via createTestRuntime.
@triggery/react Component-level testing with the React testing library on top.
@triggery/solid Solid testing via @solidjs/testing-library.
@triggery/vue Vue testing via @vue/test-utils.
@triggery/eslint-plugin Static checks that catch issues tests can miss.