mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add _.updateWith tests.
This commit is contained in:
30
test/test.js
30
test/test.js
@@ -23096,22 +23096,30 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash.update');
|
QUnit.module('update methods');
|
||||||
|
|
||||||
(function() {
|
lodashStable.each(['update', 'updateWith'], function(methodName) {
|
||||||
QUnit.test('should call `updater` with existing value on `path` of `object` and update it', function(assert) {
|
var func = _[methodName],
|
||||||
assert.expect(2);
|
oldValue = 1,
|
||||||
|
value = 2;
|
||||||
|
|
||||||
var object = { 'a': [{ 'b': { 'c': 10 } }] };
|
QUnit.test('`_.' + methodName + '` should invoke `updater` with the value on `path` of `object`', function(assert) {
|
||||||
|
assert.expect(4);
|
||||||
|
|
||||||
_.update(object, ['a', 0, 'b', 'c'], function(value) {
|
var object = { 'a': [{ 'b': { 'c': oldValue } }] },
|
||||||
assert.equal(value, 10);
|
expected = oldValue + 1;
|
||||||
return 20;
|
|
||||||
|
lodashStable.each(['a[0].b.c', ['a', '0', 'b', 'c']], function(path) {
|
||||||
|
func(object, path, function(n) {
|
||||||
|
assert.strictEqual(n, oldValue);
|
||||||
|
return ++n;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(object.a[0].b.c, expected);
|
||||||
|
object.a[0].b.c = oldValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(object.a[0].b.c, 20);
|
|
||||||
});
|
});
|
||||||
}());
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user