UNPKG

overmind

Version:
80 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _1 = require("./"); describe('Reaction', () => { test('should create reaction', () => { expect.assertions(2); let runCount = 0; const state = { foo: 'bar', }; const changeFoo = ({ state }) => { state.foo = 'bar2'; }; const actions = { changeFoo, }; const config = { state, actions, }; const app = new _1.Overmind(config); app.reaction(({ foo }) => foo, (foo) => { runCount++; expect(foo).toBe('bar2'); }); app.actions.changeFoo(); expect(runCount).toBe(1); }); test('should create deep reaction', () => { expect.assertions(2); let runCount = 0; const state = { foo: { bar: 'baz', }, }; const changeFoo = ({ state }) => { state.foo.bar = 'baz2'; }; const actions = { changeFoo, }; const config = { state, actions, }; const app = new _1.Overmind(config); app.reaction(({ foo }) => foo, (foo) => { runCount++; expect(foo.bar).toBe('baz2'); }, { nested: true }); app.actions.changeFoo(); expect(runCount).toBe(1); }); test('should throw deep reaction when invalid return object', () => { expect.assertions(1); const state = { foo: { bar: 'baz', }, }; const changeFoo = ({ state }) => { state.foo.bar = 'baz2'; }; const actions = { changeFoo, }; const config = { state, actions, }; const app = new _1.Overmind(config); expect(() => { app.reaction(({ foo }) => foo.bar, (bar) => { expect(bar).toBe('baz2'); }, { nested: true }); }).toThrow(); }); }); //# sourceMappingURL=reaction.test.js.map