add subdux test

This commit is contained in:
Yanick Champoux 2023-03-09 14:48:11 -05:00
parent e55bf7a771
commit 1555e4d289
2 changed files with 19 additions and 17 deletions

View File

@ -5,22 +5,6 @@ import { action } from './actions.js';
import { Updux, dux } from './Updux.js';
test('mutation of a subdux', async () => {
const bar = dux({
actions: {
baz: null,
},
});
bar.setMutation('baz', () => (state) => ({ ...state, x: 1 }));
const foo = dux({
subduxes: { bar },
});
const store = foo.createStore();
store.dispatch.baz();
expect(store.getState()).toMatchObject({ bar: { x: 1 } });
});
test('strings and generators', async () => {
const actionA = action('a');

View File

@ -1,6 +1,6 @@
import { test, expect } from 'vitest';
import Updux from './index.js';
import Updux, { createAction } from './index.js';
test('set a mutation', () => {
const dux = new Updux({
@ -53,3 +53,21 @@ test('default mutation', () => {
expect(dux.reducer(undefined, { type: 'foo' })).toEqual('got it');
expect(dux.reducer(undefined, { type: 'bar' })).toEqual('bar');
});
test('mutation of a subdux', () => {
const baz = createAction('baz');
const bar = new Updux({
initial: 0,
actions: {
baz,
},
});
bar.addMutation(baz, () => () => 1);
const foo = new Updux({
subduxes: { bar },
});
expect(foo.reducer(undefined, baz())).toHaveProperty('bar', 1);
});