Allow Number type in updateIn function (#67)
parent
79320ad975
commit
bc00fee109
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue