Skip to content

Commit

Permalink
fix issue when the object has a key that is one of the path's parts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
islam3zzat authored and jaredpalmer committed Apr 10, 2018
1 parent 636a670 commit 095e915
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -30,7 +30,7 @@ export function setIn(obj: any, path: string, value: any): any {

for (; i < pathArray.length - 1; i++) {
const currentPath: string = pathArray[i];
let currentObj: any = obj[currentPath];
let currentObj: any = getIn(obj, pathArray.slice(0, i + 1));

if (resVal[currentPath]) {
resVal = resVal[currentPath];
Expand Down
7 changes: 7 additions & 0 deletions test/utils.test.tsx
Expand Up @@ -190,6 +190,13 @@ describe('utils', () => {
expect(obj).toEqual({ x: 'y' });
expect(newObj).toEqual({ x: 'y', nested: ['value'] });
});

it('supports path containing key of the object', () => {
const obj = { x: 'y' };
const newObj = setIn(obj, 'a.x.c', 'value');
expect(obj).toEqual({ x: 'y' });
expect(newObj).toEqual({ x: 'y', a: { x: { c: 'value' } } });
});
});

describe('isPromise', () => {
Expand Down

0 comments on commit 095e915

Please sign in to comment.