updux/dist/splat.test.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-10-22 22:15:08 +00:00
"use strict";
2019-10-24 15:52:36 +00:00
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
const updeep_1 = __importDefault(require("updeep"));
const tracer = (chr) => updeep_1.default({ tracer: (s = '') => s + chr });
2019-10-22 22:15:08 +00:00
test('mutations, simple', () => {
2019-11-05 01:34:14 +00:00
const dux = new _1.default({
2019-10-24 15:52:36 +00:00
mutations: {
foo: () => tracer('a'),
'*': () => tracer('b'),
},
});
const store = dux.createStore();
expect(store.getState()).toEqual({ tracer: 'b' });
store.dispatch.foo();
expect(store.getState()).toEqual({ tracer: 'ba', });
store.dispatch({ type: 'bar' });
expect(store.getState()).toEqual({ tracer: 'bab', });
2019-10-22 22:15:08 +00:00
});
test('with subduxes', () => {
2019-11-05 01:34:14 +00:00
const dux = new _1.default({
2019-10-22 22:15:08 +00:00
mutations: {
2019-10-24 15:52:36 +00:00
foo: () => tracer('a'),
'*': () => tracer('b'),
bar: () => ({ bar }) => ({ bar, tracer: bar.tracer })
},
subduxes: {
2019-11-05 01:34:14 +00:00
bar: {
2019-10-24 15:52:36 +00:00
mutations: {
foo: () => tracer('d'),
'*': () => tracer('e'),
},
2019-11-05 01:34:14 +00:00
},
2019-10-24 15:52:36 +00:00
},
});
const store = dux.createStore();
expect(store.getState()).toEqual({
tracer: 'b',
bar: { tracer: 'e' }
});
store.dispatch.foo();
expect(store.getState()).toEqual({
tracer: 'ba',
bar: { tracer: 'ed' }
});
store.dispatch({ type: 'bar' });
expect(store.getState()).toEqual({
tracer: 'ede',
bar: { tracer: 'ede' }
});
});
//# sourceMappingURL=splat.test.js.map