UNPKG

reedx

Version:

Like redux but with less code

34 lines (25 loc) 1.15 kB
import { isFunction } from 'lodash' import createActions, { createFSA } from '../createActions' test('return a flux standart action', () => { const type = 'INCREMENT' const action = createFSA(type) const error = new Error('Some error') const withError = action(error) const withPayloadAndMeta = action('foo', { foo: 'foo' }) const justWithMeta = action(null, { foo: 'foo' }) const justAction = action() expect(withError).toEqual({ type, payload: error, error: true }) expect(withPayloadAndMeta).toEqual({ type, payload: 'foo', meta: { foo: 'foo' } }) expect(justWithMeta).toEqual({ type, meta: { foo: 'foo' } }) expect(justAction).toEqual({ type }) }) test('return a object with actions', () => { const increment = (state) => state + 1 const decrement = (state) => state - 1 const types = ['INCREMENT', 'DECREMENT'] const actions = createActions(types, { increment, decrement }) expect(isFunction(actions.increment)).toBeTruthy() expect(isFunction(actions.decrement)).toBeTruthy() expect(actions.increment()).toEqual({ type: 'INCREMENT' }) expect(actions.decrement()).toEqual({ type: 'DECREMENT' }) })