Allow Number type in updateIn function (#67)

This commit is contained in:
Vlad 2016-10-07 06:14:03 +03:00 committed by Aaron Jensen
parent 79320ad975
commit bc00fee109
2 changed files with 23 additions and 1 deletions

View File

@ -3,5 +3,5 @@ import reject from 'lodash/reject';
export default function splitPath(path) {
return Array.isArray(path) ?
path :
reject(path.split('.'), x => !x);
reject((path + '').split('.'), x => !x);
}

View File

@ -0,0 +1,22 @@
import { expect } from 'chai';
import splitPath from '../../lib/util/splitPath';
describe('splitPath', () => {
it('treats a number as a single step path', () => {
const path = 1;
const result = splitPath(path);
expect(result).to.deep.equal(['1']);
});
it('handles arrays', () => {
const path = ['foo', 'bar', 'x'];
const result = splitPath(path);
expect(result).to.equal(path);
});
it('handles strings separated by dots', () => {
const path = 'bar.0.y';
const result = splitPath(path);
expect(result).to.deep.equal(['bar', '0', 'y']);
});
});