@kiwa-lab/state
v2.1.0
Published
State store mock harness for kiwa — Zustand / Redux / Jotai / Valtio / MobX を統一 interface で invoke する in-process mock。 createStore / dispatch / subscribe / selectState / mockAction までを real store と同じ signature で叩ける test infra。
Maintainers
Readme
@kiwa-lab/state
State store mock harness for kiwa — Zustand / Redux / Jotai / Valtio / MobX を統一 interface で in-process から叩ける test infra。
Installation
pnpm add -D @kiwa-lab/state
# or
npm install -D @kiwa-lab/state
# or
yarn add -D @kiwa-lab/stateSupported providers
| Provider | Status | Model | |---|---|---| | Zustand | ✅ Ready | setter closure | | Redux | ✅ Ready | reducer + action | | Jotai | ✅ Ready | atom | | Valtio | ✅ Ready | proxy | | MobX | ✅ Ready | observable + action |
Quick start
import { describe, expect, it } from 'vitest';
import {
createStore,
dispatch,
subscribe,
selectState,
} from '@kiwa-lab/state';
describe('counter store', () => {
it('increment action で count が 1 増える', () => {
const store = createStore({ provider: 'redux', initialState: { count: 0 } });
const listener = subscribe(store, (s) => s);
dispatch(store, { type: 'increment', payload: 1 });
expect(selectState(store, (s) => s.count)).toBe(1);
expect(listener.calls.length).toBe(1);
});
});API reference
createStore({ provider: StateProvider, initialState }): StateStore— provider 別 store instancedispatch(store, action: Action): DispatchResult— Redux/Zustand/MobX action 発火subscribe(store, listener: StateListener): Subscription— state 変更 subscribe + traceselectState(store, selector: Selector): unknown— Jotai/Valtio selector 相当mockAction(store, creator: MockActionCreator): Action— test fixture action 生成
Test integration
vitest + /kiwa-state skill で 5 provider の store 挙動差 (reducer / setter / atom / proxy / observable) を統一 shape で verify。
License
UNLICENSED — see github.com/cardene777/kiwa.
