updux/src/mutations.test.js

31 lines
683 B
JavaScript
Raw Normal View History

2022-08-25 23:43:07 +00:00
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: {
2022-08-26 00:06:52 +00:00
x: 'potato',
2022-08-25 23:43:07 +00:00
},
actions: {
2022-08-26 00:06:52 +00:00
foo: action('foo', (x) => ({ x })),
2022-08-25 23:43:07 +00:00
bar: action('bar'),
2022-08-26 00:06:52 +00:00
},
2022-08-25 23:43:07 +00:00
});
2022-08-26 00:06:52 +00:00
dux.setMutation(dux.actions.foo, (payload, action) =>
u({
x: payload.x + action.type,
}),
);
2022-08-25 23:43:07 +00:00
2022-08-26 00:06:52 +00:00
const result = dux.reducer(undefined, dux.actions.foo('hello '));
expect(result).toEqual({
x: 'hello foo',
});
2022-08-25 23:43:07 +00:00
});