From 9788f7101b1cd3e6ea5bda14704017615e3e03df Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 30 Jan 2016 17:54:39 -0800 Subject: [PATCH] Ensure fp `unset` is immutable. [closes #1913] --- fp/_mapping.js | 3 ++- test/test-fp.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fp/_mapping.js b/fp/_mapping.js index 4d7c1fd41..614ee876c 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -174,7 +174,8 @@ exports.mutate = { }, 'set': { 'set': true, - 'setWith': true + 'setWith': true, + 'unset': true } }; diff --git a/test/test-fp.js b/test/test-fp.js index 7ac1344bd..cee1baa49 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -400,7 +400,7 @@ deepObject = { 'a': { 'b': 2, 'c': 3 } }; QUnit.test('should not mutate values', function(assert) { - assert.expect(36); + assert.expect(38); function Foo() {} Foo.prototype = { 'b': 2 }; @@ -526,6 +526,12 @@ assert.deepEqual(value, deepObject, 'fp.setWith'); assert.deepEqual(actual, { 'a': { 'b': 2, 'c': 3 }, 'd': { 'e': 4 } }, 'fp.setWith'); + + value = _.cloneDeep(deepObject); + actual = fp.unset('a.b', value); + + assert.deepEqual(value, deepObject, 'fp.unset'); + assert.deepEqual(actual, { 'a': { 'c': 3 } }, 'fp.set'); }); }());