Add keys methods tests for array-like values.

This commit is contained in:
John-David Dalton
2016-07-26 22:51:58 -07:00
parent c7e8953b68
commit de07e3f874

View File

@@ -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);