UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

78 lines (73 loc) 1.94 kB
import { arrayPush } from '../actions'; var describeArrayPush = function describeArrayPush(reducer, expect, _ref) { var fromJS = _ref.fromJS; return function () { it('should work with empty state', function () { var state = reducer(undefined, arrayPush('foo', 'myField', 'myValue')); expect(state).toEqualMap({ foo: { values: { myField: ['myValue'] } } }); }); it('should work pushing undefined to empty state', function () { var state = reducer(undefined, arrayPush('foo', 'myField')); expect(state).toEqualMap({ foo: { values: { myField: [undefined] } } }); }); it('should work with existing empty array', function () { var state = reducer(fromJS({ foo: { values: { myField: [] } } }), arrayPush('foo', 'myField', 'myValue')); expect(state).toEqualMap({ foo: { values: { myField: ['myValue'] } } }); }); it('should push at end', function () { var state = reducer(fromJS({ foo: { values: { myField: { subField: ['a', 'b', 'c'] } }, fields: { myField: { subField: [{ touched: true }, { touched: true, visited: true }, { touched: true }] } } } }), arrayPush('foo', 'myField.subField', 'newValue')); expect(state).toEqualMap({ foo: { values: { myField: { subField: ['a', 'b', 'c', 'newValue'] } }, fields: { myField: { subField: [{ touched: true }, { touched: true, visited: true }, { touched: true }, {}] } } } }); }); }; }; export default describeArrayPush;