From 49b33d667d74cc5d68441b581809891723cb2102 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 7 Mar 2016 08:04:11 -0800 Subject: [PATCH] Add `toPairs` test for inherited string keyed properties. --- test/test.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/test/test.js b/test/test.js index 67ba27682..d406ab1ac 100644 --- a/test/test.js +++ b/test/test.js @@ -22108,27 +22108,47 @@ QUnit.module('toPairs methods'); lodashStable.each(['toPairs', 'toPairsIn'], function(methodName) { - var func = _[methodName]; + var func = _[methodName], + isToPairs = methodName == 'toPairs'; - QUnit.test('`_.' + methodName + '` should create a two dimensional array of key-value pairs', function(assert) { + QUnit.test('`_.' + methodName + '` should create an array of string keyed-value pairs', function(assert) { assert.expect(1); - var object = { 'a': 1, 'b': 2 }; - assert.deepEqual(func(object), [['a', 1], ['b', 2]]); + var object = { 'a': 1, 'b': 2 }, + actual = lodashStable.sortBy(func(object), 0); + + assert.deepEqual(actual, [['a', 1], ['b', 2]]); }); QUnit.test('`_.' + methodName + '` should work with an object that has a `length` property', function(assert) { assert.expect(1); - var object = { '0': 'a', '1': 'b', 'length': 2 }; - assert.deepEqual(func(object), [['0', 'a'], ['1', 'b'], ['length', 2]]); + var object = { '0': 'a', '1': 'b', 'length': 2 }, + actual = lodashStable.sortBy(func(object), 0); + + assert.deepEqual(actual, [['0', 'a'], ['1', 'b'], ['length', 2]]); + }); + + QUnit.test('`_.' + methodName + '` should ' + (isToPairs ? 'not ' : '') + 'include inherited string keyed property values', function(assert) { + assert.expect(1); + + function Foo() { + this.a = 1; + } + Foo.prototype.b = 2; + + var expected = isToPairs ? [['a', 1]] : [['a', 1], ['b', 2]], + actual = lodashStable.sortBy(func(new Foo), 0); + + assert.deepEqual(actual, expected); }); QUnit.test('`_.' + methodName + '` should work with strings', function(assert) { assert.expect(2); lodashStable.each(['xo', Object('xo')], function(string) { - assert.deepEqual(func(string), [['0', 'x'], ['1', 'o']]); + var actual = lodashStable.sortBy(func(string), 0); + assert.deepEqual(actual, [['0', 'x'], ['1', 'o']]); }); }); });