mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Add sumBy tests.
This commit is contained in:
86
test/test.js
86
test/test.js
@@ -20389,47 +20389,6 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.sum');
|
||||
|
||||
(function() {
|
||||
var array = [6, 4, 2];
|
||||
|
||||
QUnit.test('should return the sum of an array of numbers', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(_.sum(array), 12);
|
||||
});
|
||||
|
||||
QUnit.test('should return `0` when passing empty `array` values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = lodashStable.map(empties, alwaysZero),
|
||||
actual = lodashStable.map(empties, _.sum);
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should skip `undefined` values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(_.sum([1, undefined]), 1);
|
||||
});
|
||||
|
||||
QUnit.test('should not skip `NaN` values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.deepEqual(_.sum([1, NaN]), NaN);
|
||||
});
|
||||
|
||||
QUnit.test('should not coerce values to numbers', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(_.sum(['1', '2']), '12');
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.sumBy');
|
||||
|
||||
(function() {
|
||||
@@ -20469,6 +20428,51 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('sum methods');
|
||||
|
||||
lodashStable.each(['sum', 'sumBy'], function(methodName) {
|
||||
var array = [6, 4, 2],
|
||||
func = _[methodName];
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should return the sum of an array of numbers', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(func(array), 12);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should return `0` when passing empty `array` values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = lodashStable.map(empties, alwaysZero);
|
||||
|
||||
var actual = lodashStable.map(empties, function(value) {
|
||||
return func(value);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should skip `undefined` values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(func([1, undefined]), 1);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should not skip `NaN` values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.deepEqual(func([1, NaN]), NaN);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should not coerce values to numbers', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
assert.strictEqual(func(['1', '2']), '12');
|
||||
});
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.tail');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user