UNPKG

reedx

Version:

Like redux but with less code

29 lines (21 loc) 740 B
import { isFunction } from 'lodash' import createReducer from '../createReducer' import createTypes from '../createTypes' const name = 'counter' const state = 0 const increment = (state) => state + 1 const decrement = (state) => state - 1 const handlers = { increment, decrement } const types = createTypes(name, handlers) const reducer = createReducer(state, types, handlers) test('returns a function', () => { expect(isFunction(reducer)).toBeTruthy() }) test('return the initial state', () => { expect(reducer(state, {})).toBe(0) }) test('handler actions on a state', () => { const [INCREMENT, DECREMENT] = types expect(reducer(state, { type: INCREMENT })).toBe(1) expect(reducer(state, { type: DECREMENT })).toBe(-1) })