8000 Cleanup path tests. · lodash/lodash@330c8cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 330c8cb

Browse files
committed
Cleanup path tests.
1 parent da2e8a1 commit 330c8cb

File tree

1 file changed

+93
-107
lines changed

1 file changed

+93
-107
lines changed

test/test.js

+93-107
Original file line numberDiff line numberDiff line change
@@ -7775,7 +7775,7 @@
77757775
});
77767776
});
77777777

7778-
QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of the object', function(assert) {
7778+
QUnit.test('`_.' + methodName + '` should not use the `hasOwnProperty` method of `object`', function(assert) {
77797779
assert.expect(1);
77807780

77817781
var object = { 'hasOwnProperty': null, 'a': 1 };
@@ -7797,24 +7797,22 @@
77977797
});
77987798

77997799
QUnit.test('`_.' + methodName + '` should coerce `path` to a string', function(assert) {
7800-
assert.expect(1);
7800+
assert.expect(2);
78017801

78027802
function fn() {}
78037803
fn.toString = lodashStable.constant('fn');
78047804

7805-
var expected = [1, 1, 2, 2, 3, 3, 4, 4],
7806-
objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
7807-
values = [null, undefined, fn, {}];
7805+
var object = { 'null': 1 , 'undefined': 2, 'fn': 3, '[object Object]': 4 },
7806+
paths = [null, undefined, fn, {}],
7807+
expected = lodashStable.map(paths, stubTrue);
78087808

7809-
var actual = lodashStable.transform(objects, function(result, object, index) {
7810-
var key = values[index];
7811-
lodashStable.each([key, [key]], function(path) {
7812-
var prop = _.property(key);
7813-
result.push(prop(object));
7809+
lodashStable.times(2, function(index) {
7810+
var actual = lodashStable.map(paths, function(path) {
7811+
return func(object, index ? [path] : path);
78147812
});
7815-
});
78167813

7817-
assert.deepEqual(actual, expected);
7814+
assert.deepEqual(actual, expected);
7815+
});
78187816
});
78197817

78207818
QUnit.test('`_.' + methodName + '` should work with `arguments` objects', function(assert) {
@@ -7876,28 +7874,6 @@
78767874
});
78777875
});
78787876

7879-
QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
7880-
assert.expect(2);
7881-
7882-
function Foo() {}
7883-
Foo.prototype.a = 1;
7884-
7885-
lodashStable.each(['a', ['a']], function(path) {
7886-
assert.strictEqual(func(new Foo, path), !isHas);
7887-
});
7888-
});
7889-
7890-
QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
7891-
assert.expect(2);
7892-
7893-
function Foo() {}
7894-
Foo.prototype.a = { 'b': 1 };
7895-
7896-
lodashStable.each(['a.b', ['a', 'b']], function(path) {
7897-
assert.strictEqual(func(new Foo, path), !isHas);
7898-
});
7899-
});
7900-
79017877
QUnit.test('`_.' + methodName + '` should return `true` for indexes of sparse values', function(assert) {
79027878
assert.expect(1);
79037879

@@ -7926,6 +7902,28 @@
79267902
assert.deepEqual(actual, expected);
79277903
});
79287904

7905+
QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for inherited properties', function(assert) {
7906+
assert.expect(2);
7907+
7908+
function Foo() {}
7909+
Foo.prototype.a = 1;
7910+
7911+
lodashStable.each(['a', ['a']], function(path) {
7912+
assert.strictEqual(func(new Foo, path), !isHas);
7913+
});
7914+
});
7915+
7916+
QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
7917+
assert.expect(2);
7918+
7919+
function Foo() {}
7920+
Foo.prototype.a = { 'b': 1 };
7921+
7922+
lodashStable.each(['a.b', ['a', 'b']], function(path) {
7923+
assert.strictEqual(func(new Foo, path), !isHas);
7924+
});
7925+
});
7926+
79297927
QUnit.test('`_.' + methodName + '` should return `false` when `object` is nullish', function(assert) {
79307928
assert.expect(2);
79317929

@@ -14090,28 +14088,24 @@
1409014088
assert.deepEqual(actual, expected);
1409114089
});
1409214090

14093-
QUnit.test('should coerce key to a string', function(assert) {
14094-
assert.expect(1);
14091+
QUnit.test('should coerce `path` to a string', function(assert) {
14092+
assert.expect(2);
1409514093

1409614094
function fn() {}
1409714095
fn.toString = lodashStable.constant('fn');
1409814096

14099-
var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
14100-
values = [null, undefined, fn, {}];
14097+
var object = { 'null': 1, 'undefined': 2, 'fn': 3, '[object Object]': 4 },
14098+
paths = [null, undefined, fn, {}],
14099+
expected = lodashStable.map(paths, stubTrue);
1410114100

14102-
var expected = lodashStable.transform(values, function(result) {
14103-
result.push(true, true);
14104-
});
14105-
14106-
var actual = lodashStable.transform(objects, function(result, object, index) {
14107-
var key = values[index];
14108-
lodashStable.each([key, [key]], function(path) {
14109-
var matches = _.matchesProperty(path, object[key]);
14110-
result.push(matches(object));
14101+
lodashStable.times(2, function(index) {
14102+
var actual = lodashStable.map(paths, function(path) {
14103+
var matches = _.matchesProperty(index ? [path] : path, object[path]);
14104+
return matches(object);
1411114105
});
14112-
});
1411314106

14114-
assert.deepEqual(actual, expected);
14107+
assert.deepEqual(actual, expected);
14108+
});
1411514109
});
1411614110

1411714111
QUnit.test('should match a key over a path', function(assert) {
@@ -15254,25 +15248,24 @@
1525415248
});
1525515249
});
1525615250

15257-
QUnit.test('should coerce key to a string', function(assert) {
15258-
assert.expect(1);
15251+
QUnit.test('should coerce `path` to a string', function(assert) {
15252+
assert.expect(2);
1525915253

1526015254
function fn() {}
1526115255
fn.toString = lodashStable.constant('fn');
1526215256

15263-
var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15264-
objects = [{ 'null': stubOne }, { 'undefined': stubTwo }, { 'fn': stubThree }, { '[object Object]': stubFour }],
15265-
values = [null, undefined, fn, {}];
15257+
var expected = [1, 2, 3, 4],
15258+
object = { 'null': stubOne, 'undefined': stubTwo, 'fn': stubThree, '[object Object]': stubFour },
15259+
paths = [null, undefined, fn, {}];
1526615260

15267-
var actual = lodashStable.transform(objects, function(result, object, index) {
15268-
var key = values[index];
15269-
lodashStable.each([key, [key]], function(path) {
15270-
var method = _.method(key);
15271-
result.push(method(object));
15261+
lodashStable.times(2, function(index) {
15262+
var actual = lodashStable.map(paths, function(path) {
15263+
var method = _.method(index ? [path] : path);
15264+
return method(object);
1527215265
});
15273-
});
1527415266

15275-
assert.deepEqual(actual, expected);
15267+
assert.deepEqual(actual, expected);
15268+
});
1527615269
});
1527715270

1527815271
QUnit.test('should work with inherited property values', function(assert) {
@@ -15409,25 +15402,24 @@
1540915402
});
1541015403
});
1541115404

15412-
QUnit.test('should coerce key to a string', function(assert) {
15413-
assert.expect(1);
15405+
QUnit.test('should coerce `path` to a string', function(assert) {
15406+
assert.expect(2);
1541415407

1541515408
function fn() {}
1541615409
fn.toString = lodashStable.constant('fn');
1541715410

15418-
var expected = [1, 1, 2, 2, 3, 3, 4, 4],
15419-
objects = [{ 'null': stubOne }, { 'undefined': stubTwo }, { 'fn': stubThree }, { '[object Object]': stubFour }],
15420-
values = [null, undefined, fn, {}];
15411+
var expected = [1, 2, 3, 4],
15412+
object = { 'null': stubOne, 'undefined': stubTwo, 'fn': stubThree, '[object Object]': stubFour },
15413+
paths = [null, undefined, fn, {}];
1542115414

15422-
var actual = lodashStable.transform(objects, function(result, object, index) {
15423-
var key = values[index];
15424-
lodashStable.each([key, [key]], function(path) {
15415+
lodashStable.times(2, function(index) {
15416+
var actual = lodashStable.map(paths, function(path) {
1542515417
var methodOf = _.methodOf(object);
15426-
result.push(methodOf(key));
15418+
return methodOf(index ? [path] : path);
1542715419
});
15428-
});
1542915420

15430-
assert.deepEqual(actual, expected);
15421+
assert.deepEqual(actual, expected);
15422+
});
1543115423
});
1543215424

1543315425
QUnit.test('should work with inherited property values', function(assert) {
@@ -17807,24 +17799,24 @@
1780717799
assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
1780817800
});
1780917801

17810-
QUnit.test('should coerce key to a string', function(assert) {
17811-
assert.expect(1);
17802+
QUnit.test('should coerce `path` to a string', function(assert) {
17803+
assert.expect(2);
1781217804

1781317805
function fn() {}
1781417806
fn.toString = lodashStable.constant('fn');
1781517807

17816-
var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
17817-
values = [null, undefined, fn, {}];
17808+
var expected = [1, 2, 3, 4],
17809+
object = { 'null': 1, 'undefined': 2, 'fn': 3, '[object Object]': 4 },
17810+
paths = [null, undefined, fn, {}];
1781817811

17819-
var actual = lodashStable.transform(objects, function(result, object, index) {
17820-
var key = values[index];
17821-
lodashStable.each([key, [key]], function(path) {
17822-
var prop = _.property(key);
17823-
result.push(prop(object));
17812+
lodashStable.times(2, function(index) {
17813+
var actual = lodashStable.map(paths, function(path) {
17814+
var prop = _.property(index ? [path] : path);
17815+
return prop(object);
1782417816
});
17825-
});
1782617817

17827-
assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
17818+
assert.deepEqual(actual, expected);
17819+
});
1782817820
});
1782917821

1783017822
QUnit.test('should pluck a key over a path', function(assert) {
@@ -17952,24 +17944,24 @@
1795217944
assert.deepEqual(actual, ['a', 'a', 'b', 'b']);
1795317945
});
1795417946

17955-
QUnit.test('should coerce key to a string', function(assert) {
17956-
assert.expect(1);
17947+
QUnit.test('should coerce `path` to a string', function(assert) {
17948+
assert.expect(2);
1795717949

1795817950
function fn() {}
1795917951
fn.toString = lodashStable.constant('fn');
1796017952

17961-
var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
17962-
values = [null, undefined, fn, {}];
17953+
var expected = [1, 2, 3, 4],
17954+
object = { 'null': 1, 'undefined': 2, 'fn': 3, '[object Object]': 4 },
17955+
paths = [null, undefined, fn, {}];
1796317956

17964-
var actual = lodashStable.transform(objects, function(result, object, index) {
17965-
var key = values[index];
17966-
lodashStable.each([key, [key]], function(path) {
17957+
lodashStable.times(2, function(index) {
17958+
var actual = lodashStable.map(paths, function(path) {
1796717959
var propOf = _.propertyOf(object);
17968-
result.push(propOf(key));
17960+
return propOf(index ? [path] : path);
1796917961
});
17970-
});
1797117962

17972-
assert.deepEqual(actual, [1, 1, 2, 2, 3, 3, 4, 4]);
17963+
assert.deepEqual(actual, expected);
17964+
});
1797317965
});
1797417966

1797517967
QUnit.test('should pluck a key over a path', function(assert) {
@@ -19325,25 +19317,19 @@
1932519317
});
1932619318

1932719319
QUnit.test('`_.' + methodName + '` should return the default value for `undefined` values', function(assert) {
19328-
assert.expect(1);
19320+
assert.expect(2);
1932919321

1933019322
var object = { 'a': {} },
19331-
values = empties.concat(true, new Date, 1, /x/, 'a');
19332-
19333-
var expected = lodashStable.transform(values, function(result, value) {
19334-
result.push(value, value, value, value);
19335-
});
19323+
values = empties.concat(true, new Date, 1, /x/, 'a'),
19324+
expected = lodashStable.map(values, function(value) { return [value, value]; });
1933619325

19337-
var actual = lodashStable.transform(values, function(result, value) {
19338-
lodashStable.each(['a.b', ['a', 'b']], function(path) {
19339-
result.push(
19340-
func(object, path, value),
19341-
func(null, path, value)
19342-
);
19326+
lodashStable.each(['a.b', ['a', 'b']], function(path) {
19327+
var actual = lodashStable.map(values, function(value) {
19328+
return [func(object, path, value), func(null, path, value)];
1934319329
});
19344-
});
1934519330

19346-
assert.deepEqual(actual, expected);
19331+
assert.deepEqual(actual, expected);
19332+
});
1934719333
});
1934819334

1934919335
QUnit.test('`_.' + methodName + '` should return the default value when `path` is empty', function(assert) {

0 commit comments

Comments
 (0)
0