UNPKG

react-redux-typescript

Version:
94 lines 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); console.log('\nRunning test suite...\n'); const passed = (describe) => { console.log(describe, true); }; const failed = (describe, state) => { process.exitCode = 1; console.log(describe, false, state); }; const helpers_1 = require("./helpers"); var TestHelpers1; (function (TestHelpers1) { const APP_STARTED = 'app/APP_STARTED'; const SHOW_MESSAGE = 'app/SHOW_MESSAGE'; const HIDE_MESSAGE = 'app/HIDE_MESSAGE'; const appStarted = helpers_1.createEmptyAction(APP_STARTED); const showMessage = helpers_1.createPayloadAction(SHOW_MESSAGE); const hideMessage = helpers_1.createPayloadAction(HIDE_MESSAGE); const initialState = { isLoading: true, message: undefined, }; function appReducer(state = initialState, action) { switch (action.type) { case APP_STARTED: return Object.assign({}, state, { isLoading: false }); case SHOW_MESSAGE: return Object.assign({}, state, { message: action.payload }); case HIDE_MESSAGE: return Object.assign({}, state, { message: action.payload }); default: return state; } } const state1 = appReducer(undefined, appStarted()); if (state1.isLoading === false) { passed('state1'); } else { failed('state1', state1); } const state2 = appReducer(undefined, showMessage('App Started!')); if (state2.message === 'App Started!') { passed('state2'); } else { failed('state2', state2); } const state3 = appReducer(undefined, hideMessage(undefined)); if (state3.message === undefined) { passed('state3'); } else { failed('state3', state3); } })(TestHelpers1 = exports.TestHelpers1 || (exports.TestHelpers1 = {})); const __1 = require(".."); var TestHelpers2; (function (TestHelpers2) { TestHelpers2.ActionCreators = { IncreaseCounter: new __1.ActionCreator('IncreaseCounter'), ChangeBaseCurrency: new __1.ActionCreator('ChangeBaseCurrency'), }; const initialState = { counter: 0, baseCurrency: 'EUR', }; function reducer(state = initialState, action) { if (action.type === TestHelpers2.ActionCreators.IncreaseCounter.type) { return Object.assign({}, state, { counter: action.payload }); } if (action.type === TestHelpers2.ActionCreators.ChangeBaseCurrency.type) { return Object.assign({}, state, { baseCurrency: action.payload }); } return state; } const action1 = TestHelpers2.ActionCreators.IncreaseCounter.create(4); const state1 = reducer(undefined, action1); if (state1.counter === 4) { passed('state1'); } else { failed('state1', state1); } const action2 = TestHelpers2.ActionCreators.ChangeBaseCurrency.create('USD'); const state2 = reducer(undefined, action2); if (state2.baseCurrency === 'USD') { passed('state2'); } else { failed('state2', state2); } })(TestHelpers2 = exports.TestHelpers2 || (exports.TestHelpers2 = {})); //# sourceMappingURL=helpers-test.js.map