From de07e3f87432d227d00b1c4a40d714aa6b09e8fe Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 26 Jul 2016 22:51:58 -0700 Subject: [PATCH] Add keys methods tests for array-like values. --- test/test.js | 61 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/test/test.js b/test/test.js index 6d7c695b4..a65990b49 100644 --- a/test/test.js +++ b/test/test.js @@ -12841,22 +12841,6 @@ assert.deepEqual(actual, expected); }); - QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) { - assert.expect(2); - - var expected = lodashStable.map(primitives, function(value) { - return typeof value == 'string' ? ['0'] : []; - }); - - var actual = lodashStable.map(primitives, func); - assert.deepEqual(actual, expected); - - // IE 9 doesn't box numbers in for-in loops. - numberProto.a = 1; - assert.deepEqual(func(0), isKeys ? [] : ['a']); - delete numberProto.a; - }); - QUnit.test('`_.' + methodName + '` should treat sparse arrays as dense', function(assert) { assert.expect(1); @@ -12868,16 +12852,6 @@ assert.deepEqual(actual, ['0', '1', '2']); }); - QUnit.test('`_.' + methodName + '` should not coerce nullish values to objects', function(assert) { - assert.expect(2); - - objectProto.a = 1; - lodashStable.each([null, undefined], function(value) { - assert.deepEqual(func(value), []); - }); - delete objectProto.a; - }); - QUnit.test('`_.' + methodName + '` should return keys for custom properties on arrays', function(assert) { assert.expect(1); @@ -12979,6 +12953,41 @@ delete stringProto.a; }); + QUnit.test('`_.' + methodName + '` should work with array-like objects', function(assert) { + assert.expect(1); + + var object = { '0': 'a', 'length': 1 }, + actual = func(object).sort() + + assert.deepEqual(actual, ['0', 'length']); + }); + + QUnit.test('`_.' + methodName + '` should coerce primitives to objects (test in IE 9)', function(assert) { + assert.expect(2); + + var expected = lodashStable.map(primitives, function(value) { + return typeof value == 'string' ? ['0'] : []; + }); + + var actual = lodashStable.map(primitives, func); + assert.deepEqual(actual, expected); + + // IE 9 doesn't box numbers in for-in loops. + numberProto.a = 1; + assert.deepEqual(func(0), isKeys ? [] : ['a']); + delete numberProto.a; + }); + + QUnit.test('`_.' + methodName + '` should not coerce nullish values to objects', function(assert) { + assert.expect(2); + + objectProto.a = 1; + lodashStable.each([null, undefined], function(value) { + assert.deepEqual(func(value), []); + }); + delete objectProto.a; + }); + QUnit.test('`_.' + methodName + '` skips the `constructor` property on prototype objects', function(assert) { assert.expect(3);