actions.test => ts

This commit is contained in:
Yanick Champoux 2019-10-23 17:54:37 -04:00
parent 07eaf93e48
commit e63f844bdc
2 changed files with 38 additions and 38 deletions

View File

@ -1,38 +0,0 @@
import updux from '.';
import u from 'updeep';
test( 'actions defined in effects and mutations, multi-level', () => {
const { actions } = updux({
effects: {
foo: api => next => action => { },
},
mutations: { bar: () => () => null },
subduxes: {
mysub: {
effects: { baz: api => next => action => { }, },
mutations: { quux: () => () => null },
actions: {
foo: (limit) => ({limit}),
},
},
myothersub: {
effects: {
foo: () => () => () => {},
},
}
},
});
const types = Object.keys(actions);
types.sort();
expect( types).toEqual([ 'bar', 'baz', 'foo', 'quux', ]);
expect( actions.bar() ).toEqual({ type: 'bar' });
expect( actions.bar('xxx') ).toEqual({ type: 'bar', payload: 'xxx' });
expect( actions.bar(undefined,'yyy') ).toEqual({ type: 'bar',meta: 'yyy' });
expect(actions.foo(12)).toEqual({type: 'foo', payload: { limit: 12 }});
});

38
src/actions.test.ts Normal file
View File

@ -0,0 +1,38 @@
import updux from '.';
import u from 'updeep';
const noopEffect = () => () => () => {};
test('actions defined in effects and mutations, multi-level', () => {
const {actions} = updux({
effects: {
foo: noopEffect,
},
mutations: {bar: () => () => null},
subduxes: {
mysub: {
effects: {baz: noopEffect },
mutations: {quux: () => () => null},
actions: {
foo: (limit:number) => ({limit}),
},
},
myothersub: {
effects: {
foo: noopEffect,
},
},
},
});
const types = Object.keys(actions);
types.sort();
expect(types).toEqual(['bar', 'baz', 'foo', 'quux']);
expect(actions.bar()).toEqual({type: 'bar'});
expect(actions.bar('xxx')).toEqual({type: 'bar', payload: 'xxx'});
expect(actions.bar(undefined, 'yyy')).toEqual({type: 'bar', meta: 'yyy'});
expect(actions.foo(12)).toEqual({type: 'foo', payload: {limit: 12}});
});