UNPKG

overmind

Version:
125 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const _1 = require("./"); describe('Mock', () => { test('should run action tests', () => { const state = { foo: 'bar', }; const test = ({ state, effects }) => { state.foo = effects.effect('bar2'); }; const actions = { test }; const effect = (arg) => arg; const effects = { effect }; const config = { state, actions, effects, }; const overmind = (0, _1.createOvermindMock)(config, { effect(arg) { return arg + '!!!'; }, }); overmind.actions.test(); expect(overmind.mutations).toEqual([ { method: 'set', path: 'foo', args: ['bar2!!!'], hasChangedValue: true, delimiter: '.', }, ]); }); test('should test onInitialize explicitly', () => { const state = { foo: 'bar', }; const onInitializeOvermind = ({ state }) => { state.foo += '!'; }; const actions = { onInitializeOvermind, }; const config = { actions, state, }; const overmind = (0, _1.createOvermindMock)(config, { effect() { return 'bar3'; }, }); overmind.onInitialize(); expect(overmind.mutations).toEqual([ { method: 'set', path: 'foo', args: ['bar!'], hasChangedValue: true, delimiter: '.', }, ]); }); test('should preserve getters', (done) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { expect.assertions(1); const state = { value: 0, get valuePlusTwo() { return this.value + 2; }, }; const updateValue = (context) => { context.state.value = 15; }; const actions = { updateValue }; const config = { state, actions }; const mock = (0, _1.createOvermindMock)(config); yield mock.actions.updateValue(); expect(mock.state.valuePlusTwo).toEqual(17); done(); })); test('should allow setting initial state', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { expect.assertions(1); const state = { value: 0, }; const config = { state }; const mock = (0, _1.createOvermindMock)(config, (state) => { state.value = 1; }); expect(mock.state.value).toBe(1); })); test('should allow setting initial and mock effect', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { expect.assertions(2); const state = { value: 0, }; const config = { state, actions: { runFoo({ effects }) { return effects.foo(); }, }, effects: { foo() { return 'bar'; }, }, }; const mock = (0, _1.createOvermindMock)(config, { foo() { return 'bar2'; }, }, (state) => { state.value = 1; }); expect(mock.state.value).toBe(1); expect(mock.actions.runFoo()).toBe('bar2'); })); }); //# sourceMappingURL=mock.test.js.map