mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +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.
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { slice, doubled, falsey, stubArray } from './utils.js';
|
|
import times from '../times.js';
|
|
import identity from '../identity.js';
|
|
|
|
describe('times', function() {
|
|
it('should coerce non-finite `n` values to `0`', function() {
|
|
lodashStable.each([-Infinity, NaN, Infinity], function(n) {
|
|
assert.deepStrictEqual(times(n), []);
|
|
});
|
|
});
|
|
|
|
it('should coerce `n` to an integer', function() {
|
|
var actual = times(2.6, identity);
|
|
assert.deepStrictEqual(actual, [0, 1]);
|
|
});
|
|
|
|
it('should provide correct `iteratee` arguments', function() {
|
|
var args;
|
|
|
|
times(1, function() {
|
|
args || (args = slice.call(arguments));
|
|
});
|
|
|
|
assert.deepStrictEqual(args, [0]);
|
|
});
|
|
|
|
it('should use `_.identity` when `iteratee` is nullish', function() {
|
|
var values = [, null, undefined],
|
|
expected = lodashStable.map(values, lodashStable.constant([0, 1, 2]));
|
|
|
|
var actual = lodashStable.map(values, function(value, index) {
|
|
return index ? times(3, value) : times(3);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should return an array of the results of each `iteratee` execution', function() {
|
|
assert.deepStrictEqual(times(3, doubled), [0, 2, 4]);
|
|
});
|
|
|
|
it('should return an empty array for falsey and negative `n` values', function() {
|
|
var values = falsey.concat(-1, -Infinity),
|
|
expected = lodashStable.map(values, stubArray);
|
|
|
|
var actual = lodashStable.map(values, function(value, index) {
|
|
return index ? times(value) : times();
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should return an unwrapped value when implicitly chaining', function() {
|
|
assert.deepStrictEqual(_(3).times(), [0, 1, 2]);
|
|
});
|
|
|
|
it('should return a wrapped value when explicitly chaining', function() {
|
|
assert.ok(_(3).chain().times() instanceof _);
|
|
});
|
|
});
|