Add lodash.prototype methods that return non-wrapped values.

Former-commit-id: b7ecb8c91ec9647827a80a297b966639c6580ef0
This commit is contained in:
John-David Dalton
2012-11-19 23:02:35 -08:00
parent 9d4618a223
commit bd4bff3b6b
5 changed files with 107 additions and 41 deletions

View File

@@ -697,8 +697,11 @@
object = lodash(1);
equal(object.clone() instanceof lodash, false, '_(...) wrapped values are not chainable by default: ' + basename);
equal(String(object) === '1', false, '_.prototype should not implement its own `toString` method: ' + basename);
equal(Number(object) === 1 , false, '_.prototype should not implement its own `valueOf` method: ' + basename);
equal(String(object) === '1', false, '_#toString should not be implemented: ' + basename);
equal(Number(object) === 1 , false, '_#valueOf should not be implemented: ' + basename);
object.chain();
equal(typeof object.has('x') == 'object', true, '_#has returns wrapped values when chaining: ' + basename);
start();
});

View File

@@ -1915,7 +1915,7 @@
wrapped.shift();
deepEqual(wrapped.keys().value(), ['length']);
equal(wrapped.first().value(), undefined);
equal(wrapped.first(), undefined);
});
}());
@@ -1929,7 +1929,7 @@
wrapped.splice(0, 1);
deepEqual(wrapped.keys().value(), ['length']);
equal(wrapped.first().value(), undefined);
equal(wrapped.first(), undefined);
});
}());
@@ -1957,6 +1957,52 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash(...) methods returning non-wrapped values');
(function() {
var array = [1, 2, 3];
var funcs = [
'contains',
'every',
'find',
'first',
'has',
'isArguments',
'isArray',
'isBoolean',
'isDate',
'isElement',
'isEmpty',
'isEqual',
'isFinite',
'isFunction',
'isNaN',
'isNull',
'isNumber',
'isObject',
'isPlainObject',
'isRegExp',
'isString',
'isUndefined',
'last',
'reduce',
'reduceRight',
'some'
];
_.each(funcs, function(methodName) {
test('_.' + methodName + ' should return non-wrapped values', function() {
var func = _[methodName],
result = methodName == 'reduceRight' ? func(array, _.identity) : func;
notEqual(typeof result, 'object', '_.' + methodName + ' returns non-wrapped values');
});
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash methods');
(function() {