Skip to content

Commit

Permalink
🐛 Handle empty path exception (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored and nlepage committed Dec 7, 2017
1 parent c15e0cc commit 3756f33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/immutadot/src/core/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const apply = operation => {
const curried = (pPath, ...args) => {
const path = unsafeToPath(pPath)

if (path.length === 0) throw new TypeError('path should not be empty')

const applier = (obj, appliedPaths = []) => {
const walkPath = (curObj, curPath, remPath, isCopy = false) => {
const [prop, ...pathRest] = remPath
Expand Down
4 changes: 4 additions & 0 deletions packages/immutadot/src/core/apply.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,8 @@ describe('Apply', () => {
'nested.prop.0.arr.1.val',
)
})

it('should throw an explicit error when en empty path is given as parameter', () => {
expect(() => inc({}, '')).toThrowError('path should not be empty')
})
})

0 comments on commit 3756f33

Please sign in to comment.