From 26d9cc972e8aef3254a9c509a20a0a1ae241a6dd Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 23 May 2012 01:25:34 -0400 Subject: [PATCH] Add unit test to test to ensure `_.groupBy` only adds elements to own, not inherited, properties of the `result` object. Former-commit-id: 61dcdd0f6172db66d62e97873c1bc3053e339342 --- test/test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test.js b/test/test.js index 92f426f10..8aa8418c2 100644 --- a/test/test.js +++ b/test/test.js @@ -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]); + }); }()); /*--------------------------------------------------------------------------*/