mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Add _.update.
This commit is contained in:
committed by
John-David Dalton
parent
efa1ebff16
commit
b40b555386
@@ -563,7 +563,7 @@
|
||||
deepObject = { 'a': { 'b': 2, 'c': 3 } };
|
||||
|
||||
QUnit.test('should not mutate values', function(assert) {
|
||||
assert.expect(38);
|
||||
assert.expect(40);
|
||||
|
||||
function Foo() {}
|
||||
Foo.prototype = { 'b': 2 };
|
||||
@@ -695,6 +695,12 @@
|
||||
|
||||
assert.deepEqual(value, deepObject, 'fp.unset');
|
||||
assert.deepEqual(actual, { 'a': { 'c': 3 } }, 'fp.unset');
|
||||
|
||||
value = _.cloneDeep(deepObject);
|
||||
actual = fp.update(function(x) { return x + 1; })('a.b')(value);
|
||||
|
||||
assert.deepEqual(value, deepObject, 'fp.update');
|
||||
assert.deepEqual(actual, { 'a': { 'b': 3, 'c': 3 } }, 'fp.update');
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -742,7 +748,7 @@
|
||||
deepObject = { 'a': { 'b': 2, 'c': 3 } };
|
||||
|
||||
QUnit.test('should only clone objects in `path`', function(assert) {
|
||||
assert.expect(8);
|
||||
assert.expect(9);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 1 }, 'd': { 'e': 1 } } },
|
||||
value = _.cloneDeep(object),
|
||||
@@ -765,6 +771,10 @@
|
||||
|
||||
assert.notOk('b' in actual, 'fp.unset');
|
||||
assert.strictEqual(actual.d, value.d, 'fp.unset');
|
||||
|
||||
value = _.cloneDeep(object);
|
||||
actual = fp.update(function(x) { return { 'c2': 2 }; }, 'a.b', value);
|
||||
assert.strictEqual(actual.d, value.d, 'fp.update');
|
||||
});
|
||||
}());
|
||||
|
||||
|
||||
21
test/test.js
21
test/test.js
@@ -18439,6 +18439,25 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.update');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should call `func` with existing value on `path` of `object` and update it', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': [{ 'b': { 'c': 10 } }] };
|
||||
|
||||
_.update(object, ['a', 0, 'b', 'c'], function(value) {
|
||||
assert.equal(value, 10);
|
||||
return 20;
|
||||
});
|
||||
|
||||
assert.equal(object.a[0].b.c, 20);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('set methods');
|
||||
|
||||
lodashStable.each(['set', 'setWith'], function(methodName) {
|
||||
@@ -24389,7 +24408,7 @@
|
||||
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
||||
|
||||
QUnit.test('should accept falsey arguments', function(assert) {
|
||||
assert.expect(298);
|
||||
assert.expect(299);
|
||||
|
||||
var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user