updux/dist/createStore.test.js

26 lines
839 B
JavaScript
Raw Normal View History

2025-01-31 18:16:41 +00:00
import { test, expect } from 'vitest';
import Updux, { createAction, withPayload } from './index.js';
const incr = createAction('incr', withPayload());
const dux = new Updux({
initialState: 1,
// selectors: {
// double: (x: string) => x + x,
// },
}).addMutation(incr, (i, action) => state => {
expectTypeOf(i).toEqualTypeOf();
expectTypeOf(state).toEqualTypeOf();
expectTypeOf(action).toEqualTypeOf();
return state + i;
});
suite.only('store dispatch actions', () => {
const store = dux.createStore();
test('dispatch actions', () => {
expect(store.dispatch.incr).toBeTypeOf('function');
expectTypeOf(store.dispatch.incr).toMatchTypeOf();
});
test('reducer does something', () => {
store.dispatch.incr(7);
expect(store.getState()).toEqual(8);
});
});