mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { _, empties, stubZero } from './utils.js';
|
|
|
|
describe('sum methods', function() {
|
|
lodashStable.each(['sum', 'sumBy'], function(methodName) {
|
|
var array = [6, 4, 2],
|
|
func = _[methodName];
|
|
|
|
it('`_.' + methodName + '` should return the sum of an array of numbers', function() {
|
|
assert.strictEqual(func(array), 12);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should return `0` when passing empty `array` values', function() {
|
|
var expected = lodashStable.map(empties, stubZero);
|
|
|
|
var actual = lodashStable.map(empties, function(value) {
|
|
return func(value);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should skip `undefined` values', function() {
|
|
assert.strictEqual(func([1, undefined]), 1);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should not skip `NaN` values', function() {
|
|
assert.deepStrictEqual(func([1, NaN]), NaN);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should not coerce values to numbers', function() {
|
|
assert.strictEqual(func(['1', '2']), '12');
|
|
});
|
|
});
|
|
});
|