updux/src/actions.test.ts

38 lines
788 B
TypeScript

import { test, expect } from 'vitest';
import { action } from './actions.js';
import { Updux } from './Updux.js';
test('basic action', () => {
const foo = action('foo', (thing: string) => ({ thing }));
expect(foo('bar')).toEqual({
type: 'foo',
payload: {
thing: 'bar',
},
});
});
test( "Updux config accepts actions", () => {
const foo = new Updux({
actions: {
one: action('one', (x: string) => ({x})),
two: action('two', x => x),
}
});
expect(Object.keys(foo.actions)).toHaveLength(2);
expect( foo.actions.one ).toBeTypeOf('function');
expect( foo.actions.one("potato") ).toEqual({
type: 'one',
payload: {
x: 'potato'
}
});
} )