Kea Test Utilities (kea-test-utils) is a library designed to streamline the testing of Kea logic stores, offering a fluent API for asserting logic behavior in JavaScript and TypeScript environments. Currently at version 0.2.4, it is actively maintained and ships with TypeScript types, aligning with the Kea 3.x ecosystem. The package provides core utilities such as `expectLogic` and `partial`, enabling developers to dispatch actions and then assert against the resulting state changes and subsequent dispatched actions. A critical aspect of its usage involves integrating the `testUtilsPlugin` with Kea's `resetContext` function before each test to ensure a clean, isolated testing environment. This allows for precise control over the Kea context, preventing state leakage and ensuring reliable test results. Its primary differentiator is its deep integration with Kea's internal mechanisms, providing comprehensive tools for both querying recorded action history and awaiting new actions for verification, making it indispensable for robust Kea application testing.
npm install kea-test-utilsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to test a simple Kea logic using `expectLogic` to dispatch actions, match dispatched actions, and assert against the resulting state, including setup with `resetContext` and `testUtilsPlugin`.
Remove `listenersPlugin` from the `plugins` array passed to `resetContext` in your test setup. It is now included by default in `kea`.
Ensure `resetContext({ plugins: [testUtilsPlugin] })` is called in a `beforeEach` hook in your test suite to guarantee a clean Kea context for every test.Always include `testUtilsPlugin` in the `plugins` array when calling `resetContext` in your test setup: `resetContext({ plugins: [testUtilsPlugin] })`.Update any hardcoded references from `kea.inline` to the new default or explicitly set `defaultPath` using `resetContext({ defaultPath: ['kea', 'inline'] })` if the old behavior is required.Remove `listenersPlugin` from the `plugins` array in your `resetContext` call.
Ensure `testUtilsPlugin` is passed to `resetContext` in your `beforeEach` hook: `resetContext({ plugins: [testUtilsPlugin] })`.Verify that `resetContext({ plugins: [testUtilsPlugin] })` is called within a `beforeEach` hook and that your logic is instantiated or connected correctly *after* the context has been reset.