mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
Ensure "Collection" methods treat functions as objects.
This commit is contained in:
21
test/test.js
21
test/test.js
@@ -4906,23 +4906,30 @@
|
|||||||
_.each(collectionMethods, function(methodName) {
|
_.each(collectionMethods, function(methodName) {
|
||||||
var func = _[methodName];
|
var func = _[methodName];
|
||||||
|
|
||||||
test('`_.' + methodName + '` should use `isLength` to determine whether a value is array-like', 2, function() {
|
test('`_.' + methodName + '` should use `isArrayLike` to determine whether a value is array-like', 3, function() {
|
||||||
if (func) {
|
if (func) {
|
||||||
var isIteratedAsObject = function(length) {
|
var isIteratedAsObject = function(object) {
|
||||||
var result = false;
|
var result = false;
|
||||||
func({ 'length': length }, function() { result = true; }, 0);
|
func(object, function() { result = true; }, 0);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
|
var values = [-1, '1', 1.1, Object(1), MAX_SAFE_INTEGER + 1],
|
||||||
expected = _.map(values, _.constant(true)),
|
expected = _.map(values, _.constant(true));
|
||||||
actual = _.map(values, isIteratedAsObject);
|
|
||||||
|
var actual = _.map(values, function(length) {
|
||||||
|
return isIteratedAsObject({ 'length': length });
|
||||||
|
});
|
||||||
|
|
||||||
|
var Foo = function(a) {};
|
||||||
|
Foo.a = 1;
|
||||||
|
|
||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
ok(!isIteratedAsObject(0));
|
ok(isIteratedAsObject(Foo));
|
||||||
|
ok(!isIteratedAsObject({ 'length': 0 }));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(3);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user