2023-09-06 19:09:45 +00:00
|
|
|
import { test, expect } from 'vitest';
|
2024-08-08 13:28:44 +00:00
|
|
|
import Updux, { createAction, withPayload } from './index.js';
|
2023-09-06 19:09:45 +00:00
|
|
|
|
2024-08-08 13:28:44 +00:00
|
|
|
const incr = createAction('incr', withPayload<number>());
|
2023-09-06 19:09:45 +00:00
|
|
|
|
2024-08-08 13:28:44 +00:00
|
|
|
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
|
2023-09-06 19:09:45 +00:00
|
|
|
});
|
|
|
|
|
2024-08-08 13:28:44 +00:00
|
|
|
suite.only('store dispatch actions', () => {
|
2023-09-06 19:09:45 +00:00
|
|
|
const store = dux.createStore();
|
|
|
|
|
2024-08-08 13:28:44 +00:00
|
|
|
test('dispatch actions', () => {
|
|
|
|
expect(store.dispatch.incr).toBeTypeOf('function');
|
|
|
|
expectTypeOf(store.dispatch.incr).toMatchTypeOf<Function>();
|
2023-09-06 19:09:45 +00:00
|
|
|
});
|
|
|
|
|
2024-08-08 13:28:44 +00:00
|
|
|
test('reducer does something', () => {
|
|
|
|
store.dispatch.incr(7);
|
|
|
|
expect(store.getState()).toEqual(8);
|
2023-09-06 19:09:45 +00:00
|
|
|
});
|
|
|
|
});
|