From bc00fee109f51f89bdb9f8b8b4756e236f0b84b6 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 7 Oct 2016 06:14:03 +0300 Subject: [PATCH] Allow Number type in updateIn function (#67) --- lib/util/splitPath.js | 2 +- test/util/splitPath-spec.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/util/splitPath-spec.js diff --git a/lib/util/splitPath.js b/lib/util/splitPath.js index 8a55be0..5a60555 100644 --- a/lib/util/splitPath.js +++ b/lib/util/splitPath.js @@ -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); } diff --git a/test/util/splitPath-spec.js b/test/util/splitPath-spec.js new file mode 100644 index 0000000..ac95e22 --- /dev/null +++ b/test/util/splitPath-spec.js @@ -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']); + }); +});