updeep-remeda/test/in-spec.js
2015-08-04 22:28:31 -07:00

36 lines
1.0 KiB
JavaScript

import { expect } from 'chai';
import updateIn from '../lib/updateIn';
describe('u.in', () => {
it('can update a single path described with a string', () => {
const obj = { a: { b: 0 } };
const result = updateIn('a.b', 3, obj);
expect(result).to.eql({ a: { b: 3 } });
});
it('can update a single path described with a string with a function', () => {
const inc = x => x + 1;
const obj = { a: { b: 0 } };
const result = updateIn('a.b', inc, obj);
expect(result).to.eql({ a: { b: 1 } });
});
it('can update a single path described with an array', () => {
const obj = { a: { b: 0 } };
const result = updateIn(['a', 'b'], 3, obj);
expect(result).to.eql({ a: { b: 3 } });
});
it('can update arrays', () => {
const obj = { a: [0, 0, 0] };
const result = updateIn('a.1', 3, obj);
expect(result).to.eql({ a: [0, 3, 0] });
});
it('can be partially applied', () => {
const obj = { a: { b: 0 } };
const result = updateIn('a.b')(3)(obj);
expect(result).to.eql({ a: { b: 3 } });
});
});