@stateloom/testing
v1.0.0-alpha.0
Published
Test utilities for `@stateloom/*` packages. Provides mock implementations, scope helpers, and async utilities for testing reactive state.
Readme
@stateloom/testing
Test utilities for @stateloom/* packages. Provides mock implementations, scope helpers, and async utilities for testing reactive state.
Install
pnpm add -D @stateloom/testingQuick Start
import { createTestScope, mockSubscribable, collectValues } from '@stateloom/testing';
import { signal, computed } from '@stateloom/core';
// Isolated test scope
const scope = createTestScope();
const count = scope.run(() => signal(0));
// Collect reactive values over time
const values = collectValues(count);
count.set(1);
count.set(2);
expect(values()).toEqual([0, 1, 2]);
// Mock subscribable for unit tests
const mock = mockSubscribable(42);
expect(mock.get()).toBe(42);
mock.set(99);Exports
| Export | Description |
| --------------------------------------- | ------------------------------------------ |
| createTestScope() | Create an isolated scope for testing |
| mockSubscribable(initial) | Create a mock Subscribable<T> |
| mockStore(state) | Create a mock store matching StoreApi<T> |
| collectValues(subscribable) | Record all emitted values into an array |
| flushEffects() | Synchronously flush pending effects |
| waitForUpdate(subscribable, options?) | Await the next value change |
Documentation
Full documentation with API reference, patterns, and framework testing examples: docs/api/testing
License
MIT
