updux/src/reducer.test.js

33 lines
740 B
JavaScript
Raw Normal View History

2021-10-15 16:41:58 +00:00
import u from 'updeep';
2021-10-07 16:54:04 +00:00
2021-10-15 16:41:58 +00:00
import { Updux } from './Updux';
2021-10-07 16:54:04 +00:00
2021-10-15 16:41:58 +00:00
test('basic reducer', () => {
2021-10-07 16:54:04 +00:00
const dux = new Updux({});
2021-10-15 16:41:58 +00:00
expect(typeof dux.reducer).toBe('function');
2021-10-07 16:54:04 +00:00
2021-10-15 16:41:58 +00:00
expect(dux.reducer({ a: 1 }, { type: 'foo' })).toMatchObject({a:1}); // noop
2021-10-07 16:54:04 +00:00
});
2021-10-15 16:41:58 +00:00
test('basic upreducer', () => {
2021-10-07 16:54:04 +00:00
const dux = new Updux({});
2021-10-15 16:41:58 +00:00
expect(typeof dux.upreducer).toBe('function');
2021-10-07 16:54:04 +00:00
2021-10-15 16:41:58 +00:00
expect(dux.upreducer({type:'foo'})({ a: 1 })).toMatchObject({a:1}); // noop
2021-10-07 16:54:04 +00:00
});
2021-10-15 16:41:58 +00:00
test('reducer with action', () => {
2021-10-07 16:54:04 +00:00
const dux = new Updux({
actions: {
inc: null,
},
mutations: {
inc: () => u({ a: (x) => x + 1 }),
},
});
2021-10-15 16:41:58 +00:00
expect(dux.reducer({ a: 1 }, { type: 'inc' })).toMatchObject({a:2});
2021-10-07 16:54:04 +00:00
});