mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add unit tests for exiting early from _.forEach, _.forIn, _.forOwn.
Former-commit-id: 18d55054989d3b55afce1f4d604cd274eb9289c8
This commit is contained in:
21
test/test.js
21
test/test.js
@@ -575,6 +575,27 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_.each(['forEach', 'forIn', 'forOwn'], function(methodName) {
|
||||||
|
var func = _[methodName];
|
||||||
|
QUnit.module('lodash.' + methodName + ' can exit early');
|
||||||
|
|
||||||
|
test('can exit early when iterating arrays', function() {
|
||||||
|
var array = [1, 2, 3],
|
||||||
|
values = [];
|
||||||
|
|
||||||
|
func(array, function(value) { values.push(value); return false; });
|
||||||
|
deepEqual(values, [1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('can exit early when iterating objects', function() {
|
||||||
|
var object = { 'a': 1, 'b': 2, 'c': 3 },
|
||||||
|
values = [];
|
||||||
|
|
||||||
|
func(object, function(value) { values.push(value); return false; });
|
||||||
|
equal(values.length, 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('lodash.groupBy');
|
QUnit.module('lodash.groupBy');
|
||||||
|
|||||||
Reference in New Issue
Block a user