updux/src/actions.test.js

38 lines
772 B
JavaScript
Raw Normal View History

2022-08-25 18:19:45 +00:00
import { test, expect } from 'vitest';
import { action } from './actions.js';
2022-08-25 20:36:37 +00:00
import { Updux } from './Updux.js';
2022-08-25 18:19:45 +00:00
test('basic action', () => {
2022-08-25 23:43:07 +00:00
const foo = action('foo', (thing) => ({ thing }));
2022-08-25 18:19:45 +00:00
expect(foo('bar')).toEqual({
type: 'foo',
payload: {
thing: 'bar',
},
});
});
2022-08-25 20:36:37 +00:00
test( "Updux config accepts actions", () => {
const foo = new Updux({
actions: {
2022-08-25 23:43:07 +00:00
one: action('one', (x) => ({x})),
2022-08-25 20:36:37 +00:00
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'
}
});
} )