mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Add _.setWith tests.
This commit is contained in:
@@ -9453,12 +9453,12 @@
|
||||
* @returns {Object} Returns `object`.
|
||||
* @example
|
||||
*
|
||||
* _.setWith({ '0': {} }, '[0][1][2]', 3, function(value) {
|
||||
* _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, function(value) {
|
||||
* if (!_.isObject(value)) {
|
||||
* return {};
|
||||
* }
|
||||
* });
|
||||
* // => { '0': { '1': { '2': 3 } } }
|
||||
* // => { '0': { '1': { '2': 3 }, 'length': 2 } }
|
||||
*/
|
||||
function setWith(object, path, value, customizer) {
|
||||
customizer = typeof customizer == 'function' ? customizer : undefined;
|
||||
|
||||
23
test/test.js
23
test/test.js
@@ -1016,7 +1016,7 @@
|
||||
|
||||
test('`_.' + methodName + '` should work with a `customizer` that returns `undefined`', 1, function() {
|
||||
var expected = { 'a': undefined };
|
||||
deepEqual(func({}, expected, _.identity), expected);
|
||||
deepEqual(func({}, expected, _.constant(undefined)), expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13404,6 +13404,27 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.setWith');
|
||||
|
||||
(function() {
|
||||
test('should work with a `customizer` callback', 1, function() {
|
||||
var actual = _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, function(value) {
|
||||
if (!_.isObject(value)) {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(actual, { '0': { '1': { '2': 3 }, 'length': 2 } });
|
||||
});
|
||||
|
||||
test('should work with a `customizer` that returns `undefined`', 1, function() {
|
||||
var actual = _.setWith({}, 'a[0].b.c', 4, _.constant(undefined));
|
||||
deepEqual(actual, { 'a': [{ 'b': { 'c': 4 } }] });
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('set methods');
|
||||
|
||||
_.each(['set', 'setWith'], function(methodName) {
|
||||
|
||||
Reference in New Issue
Block a user