test updux takes in actions

This commit is contained in:
Yanick Champoux 2023-03-06 13:04:51 -05:00
parent 13eeb86e05
commit d1ed23de2c
2 changed files with 25 additions and 18 deletions

View File

@ -5,24 +5,6 @@ import { action } from './actions.js';
import { Updux } from './Updux.js';
test('Updux config accepts actions', () => {
const foo = new Updux({
actions: {
one: action('one', (x) => ({ 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',
},
});
});
test('throw if double action', () => {

View File

@ -39,3 +39,28 @@ test('subduxes actions', () => {
expect(foo.actions.bar(2)).toHaveProperty('type', 'bar');
expect(foo.actions.baz()).toHaveProperty('type', 'baz');
});
test('Updux config accepts actions', () => {
const foo = new Updux({
actions: {
one: createAction(
'one',
withPayload((x) => ({ x })),
),
two: createAction(
'two',
withPayload((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',
},
});
});