mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Add more isLength tests.
This commit is contained in:
25
test/test.js
25
test/test.js
@@ -4931,22 +4931,19 @@
|
||||
_.each(collectionMethods, function(methodName) {
|
||||
var func = _[methodName];
|
||||
|
||||
test('`_.' + methodName + '` should treat objects with lengths of `0` as array-like', 1, function() {
|
||||
var pass = true;
|
||||
func({ 'length': 0 }, function() { pass = false; }, 0);
|
||||
ok(pass);
|
||||
});
|
||||
test('`_.' + methodName + '` should use `isLength` to determine whether a value is array-like', 2, function() {
|
||||
function isIteratedAsObject(length) {
|
||||
var result = false;
|
||||
func({ 'length': length }, function() { result = true; }, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
test('`_.' + methodName + '` should not treat objects with negative lengths as array-like', 1, function() {
|
||||
var pass = false;
|
||||
func({ 'length': -1 }, function() { pass = true; }, 0);
|
||||
ok(pass);
|
||||
});
|
||||
var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
|
||||
expected = _.map(values, _.constant(true)),
|
||||
actual = _.map(values, isIteratedAsObject);
|
||||
|
||||
test('`_.' + methodName + '` should not treat objects with non-number lengths as array-like', 1, function() {
|
||||
var pass = false;
|
||||
func({ 'length': '0' }, function() { pass = true; }, 0);
|
||||
ok(pass);
|
||||
deepEqual(actual, expected);
|
||||
ok(!isIteratedAsObject(0));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user