typescript
Yanick Champoux 2021-10-07 12:54:04 -04:00
parent 1759ce16c6
commit 0ecb1059ee
1 changed files with 33 additions and 0 deletions

33
src/reducer.test.js Normal file
View File

@ -0,0 +1,33 @@
import { test } from 'tap';
import u from '@yanick/updeep';
import { Updux } from './Updux.js';
test('basic reducer', async (t) => {
const dux = new Updux({});
t.type(dux.reducer, 'function');
t.same(dux.reducer({ a: 1 }, { type: 'foo' }), { a: 1 }, 'noop');
});
test('basic upreducer', async (t) => {
const dux = new Updux({});
t.type(dux.upreducer, 'function');
t.same(dux.upreducer({ type: 'foo' })({ a: 1 }), { a: 1 }, 'noop');
});
test('reducer with action', async (t) => {
const dux = new Updux({
actions: {
inc: null,
},
mutations: {
inc: () => u({ a: (x) => x + 1 }),
},
});
t.same(dux.reducer({ a: 1 }, { type: 'inc' }), { a: 2 });
});