Add _.meanBy.

This commit is contained in:
Tucker Whitehouse
2016-03-24 15:37:07 -04:00
committed by John-David Dalton
parent 271f64ee3f
commit 06316f1d47
3 changed files with 83 additions and 4 deletions

View File

@@ -12010,6 +12010,19 @@
}
});
QUnit.test('`_.meanBy` should use `_.iteratee` internally', function(assert) {
assert.expect(1);
if (!isModularize) {
_.iteratee = getPropA;
assert.strictEqual(_.meanBy(objects), 2 / 3);
_.iteratee = iteratee;
}
else {
skipAssert(assert);
}
});
QUnit.test('`_.minBy` should use `_.iteratee` internally', function(assert) {
assert.expect(1);
@@ -13958,6 +13971,44 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.meanBy');
(function() {
var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }];
QUnit.test('should work with an `iteratee` argument', function(assert) {
assert.expect(1);
var actual = _.meanBy(objects, function(object) {
return object.a;
});
assert.deepEqual(actual, 2);
});
QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
assert.expect(1);
var args;
_.meanBy(objects, function() {
args || (args = slice.call(arguments));
});
assert.deepEqual(args, [{ 'a': 2 }]);
});
QUnit.test('should work with "_.property" shorthands', function(assert) {
assert.expect(2);
var arrays = [[2], [3], [1]];
assert.strictEqual(_.meanBy(arrays, 0), 2);
assert.strictEqual(_.meanBy(objects, 'a'), 2);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.memoize');
(function() {
@@ -25146,7 +25197,7 @@
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
QUnit.test('should accept falsey arguments', function(assert) {
assert.expect(307);
assert.expect(308);
var emptyArrays = lodashStable.map(falsey, alwaysEmptyArray);