Add unit test to test to ensure _.groupBy only adds elements to own, not inherited, properties of the result object.

Former-commit-id: 61dcdd0f6172db66d62e97873c1bc3053e339342
This commit is contained in:
John-David Dalton
2012-05-23 01:25:34 -04:00
parent 52ae87812e
commit 26d9cc972e

View File

@@ -204,6 +204,15 @@
deepEqual(actual, { '1': [1.3], '2': [2.1, 2.4] });
});
test('should only add elements to own, not inherited, properties', function() {
var actual = _.groupBy([1.3, 2.1, 2.4], function(num) {
return Math.floor(num) > 1 ? 'hasOwnProperty' : 'constructor';
});
deepEqual(actual.constructor, [1.3]);
deepEqual(actual.hasOwnProperty, [2.1, 2.4]);
});
}());
/*--------------------------------------------------------------------------*/