31 lines
659 B
JavaScript
31 lines
659 B
JavaScript
|
import { test, expect } from 'vitest';
|
||
|
import schema from 'json-schema-shorthand';
|
||
|
import u from 'updeep';
|
||
|
|
||
|
import { action } from './actions.js';
|
||
|
|
||
|
import { Updux } from './Updux.js';
|
||
|
|
||
|
test('set a mutation', () => {
|
||
|
const dux = new Updux({
|
||
|
initial: {
|
||
|
x: "potato",
|
||
|
},
|
||
|
actions: {
|
||
|
foo: action('foo', (x) => ({x})),
|
||
|
bar: action('bar'),
|
||
|
}
|
||
|
});
|
||
|
|
||
|
dux.setMutation( dux.actions.foo, (payload,action) => u({
|
||
|
x: payload.x + action.type
|
||
|
}) );
|
||
|
|
||
|
const result = dux.reducer(undefined,dux.actions.foo("hello "));
|
||
|
expect( result ).toEqual({
|
||
|
x: "hello foo"
|
||
|
})
|
||
|
|
||
|
|
||
|
});
|