mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Add assignValue and assignMergeValue helpers to make value assignments more consistent across methods.
This commit is contained in:
44
test/test.js
44
test/test.js
@@ -5107,6 +5107,30 @@
|
||||
});
|
||||
});
|
||||
|
||||
_.each(['assign', 'assignWith', 'defaults', 'extend', 'extendWith', 'merge', 'mergeWith'], function(methodName) {
|
||||
var func = _[methodName];
|
||||
|
||||
test('`_.' + methodName + '` should not assign values that are the same as their destinations', 4, function() {
|
||||
_.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
|
||||
if (defineProperty) {
|
||||
var object = {},
|
||||
pass = true;
|
||||
|
||||
defineProperty(object, 'a', {
|
||||
'get': _.constant(value),
|
||||
'set': function() { pass = false; }
|
||||
});
|
||||
|
||||
func(object, { 'a': value }, _.identity);
|
||||
ok(pass, value);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
_.each(['assignWith', 'extendWith', 'mergeWith'], function(methodName) {
|
||||
var func = _[methodName],
|
||||
isMergeWith = methodName == 'mergeWith';
|
||||
@@ -5160,26 +5184,6 @@
|
||||
actual = func({ 'a': 1 }, callback, { 'c': 3 });
|
||||
deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 });
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should not assign the `customizer` result if it is the same as the destination value', 4, function() {
|
||||
_.each(['a', ['a'], { 'a': 1 }, NaN], function(value) {
|
||||
if (defineProperty) {
|
||||
var object = {},
|
||||
pass = true;
|
||||
|
||||
defineProperty(object, 'a', {
|
||||
'get': _.constant(value),
|
||||
'set': function() { pass = false; }
|
||||
});
|
||||
|
||||
func(object, { 'a': value }, _.identity);
|
||||
ok(pass);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user