updux/src/createStore.test.ts
2024-08-08 09:28:44 -04:00

31 lines
913 B
TypeScript

import { test, expect } from 'vitest';
import Updux, { createAction, withPayload } from './index.js';
const incr = createAction('incr', withPayload<number>());
const dux = new Updux({
initialState: 1,
// selectors: {
// double: (x: string) => x + x,
// },
}).addMutation(incr, (i, action) => state => {
expectTypeOf(i).toEqualTypeOf<number>();
expectTypeOf(state).toEqualTypeOf<number>();
expectTypeOf(action).toEqualTypeOf<{ type: 'incr', payload: number; }>();
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<Function>();
});
test('reducer does something', () => {
store.dispatch.incr(7);
expect(store.getState()).toEqual(8);
});
});