mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Add more _.forIn iteration tests and prep support for Error object iteration.
Former-commit-id: 3676681717d0648c9f96570a4952f7c35e6a9bec
This commit is contained in:
41
test/test.js
41
test/test.js
@@ -999,12 +999,25 @@
|
||||
|
||||
(function() {
|
||||
test('iterates over inherited properties', function() {
|
||||
function Dog(name) { this.name = name; }
|
||||
Dog.prototype.bark = function() { /* Woof, woof! */ };
|
||||
function Foo() { this.a = 1; }
|
||||
Foo.prototype.b = 2;
|
||||
|
||||
var keys = [];
|
||||
_.forIn(new Dog('Dagny'), function(value, key) { keys.push(key); });
|
||||
deepEqual(keys.sort(), ['bark', 'name']);
|
||||
_.forIn(new Foo, function(value, key) { keys.push(key); });
|
||||
deepEqual(keys.sort(), ['a', 'b']);
|
||||
});
|
||||
|
||||
test('fixes the JScript [[DontEnum]] bug with inherited properties (test in IE < 9)', function() {
|
||||
function Foo() {}
|
||||
Foo.prototype = shadowedObject;
|
||||
|
||||
function Bar() {}
|
||||
Bar.prototype = new Foo;
|
||||
Bar.prototype.constructor = Bar;
|
||||
|
||||
var keys = [];
|
||||
_.forIn(shadowedObject, function(value, key) { keys.push(key); });
|
||||
deepEqual(keys.sort(), shadowedProps);
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -1035,6 +1048,26 @@
|
||||
deepEqual(keys.sort(), shadowedProps);
|
||||
});
|
||||
|
||||
test('lodash.' + methodName + ' does not iterate over non-enumerable properties (test in IE < 9)', function() {
|
||||
_.forOwn({
|
||||
'Array': Array.prototype,
|
||||
'Boolean': Boolean.prototype,
|
||||
'Date': Date.prototype,
|
||||
'Error': Error.prototype,
|
||||
'Function': Function.prototype,
|
||||
'Object': Object.prototype,
|
||||
'Number': Number.prototype,
|
||||
'TypeError': TypeError.prototype,
|
||||
'RegExp': RegExp.prototype,
|
||||
'String': String.prototype
|
||||
},
|
||||
function(object, builtin) {
|
||||
var keys = [];
|
||||
func(object, function(value, key) { keys.push(key); });
|
||||
deepEqual(keys, [], 'non-enumerable properties on ' + builtin + '.prototype');
|
||||
});
|
||||
});
|
||||
|
||||
test('lodash.' + methodName + ' skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() {
|
||||
function Foo() {}
|
||||
Foo.prototype.a = 1;
|
||||
|
||||
Reference in New Issue
Block a user