25 lines
1003 B
JavaScript
25 lines
1003 B
JavaScript
|
import Updux, { createAction } from './index.js';
|
||
|
test('asDux', () => {
|
||
|
const actionA = createAction('actionA');
|
||
|
const defaultMutation = () => (state) => state + 1;
|
||
|
const dux = new Updux({
|
||
|
initialState: 13,
|
||
|
actions: { actionA },
|
||
|
})
|
||
|
.setDefaultMutation(defaultMutation)
|
||
|
.addReaction((api) => (state) => { })
|
||
|
.addEffect((api) => (next) => (action) => next(action));
|
||
|
const asDux = dux.asDux;
|
||
|
expect(asDux.initialState).toEqual(13);
|
||
|
expect(asDux.reducer).toBeTypeOf('function');
|
||
|
expect(asDux.actions.actionA()).toMatchObject({ type: 'actionA' });
|
||
|
expect(asDux.effects).toHaveLength(1);
|
||
|
expect(asDux.reactions).toHaveLength(1);
|
||
|
const newDux = new Updux(asDux);
|
||
|
expect(newDux.initialState).toEqual(13);
|
||
|
expect(newDux.reducer).toBeTypeOf('function');
|
||
|
expect(newDux.actions.actionA()).toMatchObject({ type: 'actionA' });
|
||
|
expect(newDux.effects).toHaveLength(1);
|
||
|
expect(newDux.reactions).toHaveLength(1);
|
||
|
});
|