reducer
This commit is contained in:
parent
1759ce16c6
commit
0ecb1059ee
33
src/reducer.test.js
Normal file
33
src/reducer.test.js
Normal 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 });
|
||||
});
|
Loading…
Reference in New Issue
Block a user