mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Fix and cleanup [[DontEnum]] unit test.
Former-commit-id: 9e47eeb03c88a52d2e1d6dd2c0373c2df2f576fe
This commit is contained in:
61
test/test.js
61
test/test.js
@@ -75,27 +75,17 @@
|
|||||||
var setDescriptor = (function() {
|
var setDescriptor = (function() {
|
||||||
try {
|
try {
|
||||||
var o = {},
|
var o = {},
|
||||||
fn = (fn = Object.defineProperty)(o, o, o) && fn;
|
fn = Object.defineProperty,
|
||||||
|
result = fn(o, o, o) && fn;
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
return fn;
|
return result;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/** Shortcut used to convert array-like objects to arrays */
|
/** Shortcut used to convert array-like objects to arrays */
|
||||||
var slice = Array.prototype.slice;
|
var slice = Array.prototype.slice;
|
||||||
|
|
||||||
/** Used to check problem JScript properties (a.k.a. the [[DontEnum]] bug) */
|
/** Used to check problem JScript properties (a.k.a. the [[DontEnum]] bug) */
|
||||||
var shadowed = {
|
var shadowedProps = [
|
||||||
'constructor': 1,
|
|
||||||
'hasOwnProperty': 2,
|
|
||||||
'isPrototypeOf': 3,
|
|
||||||
'propertyIsEnumerable': 4,
|
|
||||||
'toLocaleString': 5,
|
|
||||||
'toString': 6,
|
|
||||||
'valueOf': 7
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Used to check problem JScript properties too */
|
|
||||||
var shadowedKeys = [
|
|
||||||
'constructor',
|
'constructor',
|
||||||
'hasOwnProperty',
|
'hasOwnProperty',
|
||||||
'isPrototypeOf',
|
'isPrototypeOf',
|
||||||
@@ -105,6 +95,9 @@
|
|||||||
'valueOf'
|
'valueOf'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** Used to check problem JScript properties too */
|
||||||
|
var shadowedObject = _.invert(shadowedProps);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -414,10 +407,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should clone problem JScript properties (test in IE < 9)', function() {
|
test('should clone problem JScript properties (test in IE < 9)', function() {
|
||||||
deepEqual(_.clone(shadowed), shadowed);
|
deepEqual(_.clone(shadowedObject), shadowedObject);
|
||||||
notEqual(_.clone(shadowed), shadowed);
|
notEqual(_.clone(shadowedObject), shadowedObject);
|
||||||
deepEqual(_.cloneDeep(shadowed), shadowed);
|
deepEqual(_.cloneDeep(shadowedObject), shadowedObject);
|
||||||
notEqual(_.cloneDeep(shadowed), shadowed);
|
notEqual(_.cloneDeep(shadowedObject), shadowedObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each([
|
_.each([
|
||||||
@@ -880,8 +873,8 @@
|
|||||||
|
|
||||||
test('lodash.' + methodName + ' fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
test('lodash.' + methodName + ' fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
||||||
var keys = [];
|
var keys = [];
|
||||||
func(shadowed, function(value, key) { keys.push(key); });
|
func(shadowedObject, function(value, key) { keys.push(key); });
|
||||||
deepEqual(keys.sort(), shadowedKeys);
|
deepEqual(keys.sort(), shadowedProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
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() {
|
||||||
@@ -910,9 +903,9 @@
|
|||||||
|
|
||||||
test('lodash.' + methodName + ' should assign problem JScript properties (test in IE < 9)', function() {
|
test('lodash.' + methodName + ' should assign problem JScript properties (test in IE < 9)', function() {
|
||||||
var object = {
|
var object = {
|
||||||
'constructor': 1,
|
'constructor': '0',
|
||||||
'hasOwnProperty': 2,
|
'hasOwnProperty': '1',
|
||||||
'isPrototypeOf': 3,
|
'isPrototypeOf': '2',
|
||||||
'propertyIsEnumerable': undefined,
|
'propertyIsEnumerable': undefined,
|
||||||
'toLocaleString': undefined,
|
'toLocaleString': undefined,
|
||||||
'toString': undefined,
|
'toString': undefined,
|
||||||
@@ -920,13 +913,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var source = {
|
var source = {
|
||||||
'propertyIsEnumerable': 4,
|
'propertyIsEnumerable': '3',
|
||||||
'toLocaleString': 5,
|
'toLocaleString': '4',
|
||||||
'toString': 6,
|
'toString': '5',
|
||||||
'valueOf': 7
|
'valueOf': '6'
|
||||||
};
|
};
|
||||||
|
|
||||||
deepEqual(func(object, source), shadowed);
|
deepEqual(func(object, source), shadowedObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
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() {
|
||||||
@@ -1192,7 +1185,7 @@
|
|||||||
var args = arguments;
|
var args = arguments;
|
||||||
|
|
||||||
test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
||||||
equal(_.isEmpty(shadowed), false);
|
equal(_.isEmpty(shadowedObject), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() {
|
test('skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() {
|
||||||
@@ -1235,7 +1228,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
||||||
strictEqual(_.isEqual(shadowed, {}), false);
|
strictEqual(_.isEqual(shadowedObject, {}), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `true` for like-objects from different documents', function() {
|
test('should return `true` for like-objects from different documents', function() {
|
||||||
@@ -1434,7 +1427,7 @@
|
|||||||
Foo.prototype.a = 1;
|
Foo.prototype.a = 1;
|
||||||
|
|
||||||
deepEqual(_.keys(Foo.prototype), ['a']);
|
deepEqual(_.keys(Foo.prototype), ['a']);
|
||||||
deepEqual(_.keys(shadowed).sort(), shadowedKeys);
|
deepEqual(_.keys(shadowedObject).sort(), shadowedProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() {
|
test('skips the prototype property of functions (test in Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1)', function() {
|
||||||
@@ -2186,7 +2179,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() {
|
||||||
equal(_.size(shadowed), 7);
|
equal(_.size(shadowedObject), 7);
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each({
|
_.each({
|
||||||
@@ -2655,8 +2648,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should filter by problem JScript properties (test in IE < 9)', function() {
|
test('should filter by problem JScript properties (test in IE < 9)', function() {
|
||||||
var collection = [shadowed];
|
var collection = [shadowedObject];
|
||||||
deepEqual(_.where(collection, shadowed), [shadowed]);
|
deepEqual(_.where(collection, shadowedObject), [shadowedObject]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with an object for `collection`', function() {
|
test('should work with an object for `collection`', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user