mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Add initial test files from lodash v4. (#4172)
* 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.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
58
test/spread.js
Normal file
58
test/spread.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { slice, _, stubTrue, falsey } from './utils.js';
|
||||
|
||||
describe('spread', function() {
|
||||
function fn(a, b, c) {
|
||||
return slice.call(arguments);
|
||||
}
|
||||
|
||||
it('should spread arguments to `func`', function() {
|
||||
var spread = _.spread(fn),
|
||||
expected = [1, 2];
|
||||
|
||||
assert.deepStrictEqual(spread([1, 2]), expected);
|
||||
assert.deepStrictEqual(spread([1, 2], 3), expected);
|
||||
});
|
||||
|
||||
it('should accept a falsey `array`', function() {
|
||||
var spread = _.spread(stubTrue),
|
||||
expected = lodashStable.map(falsey, stubTrue);
|
||||
|
||||
var actual = lodashStable.map(falsey, function(array, index) {
|
||||
try {
|
||||
return index ? spread(array) : spread();
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should work with `start`', function() {
|
||||
var spread = _.spread(fn, 1),
|
||||
expected = [1, 2, 3];
|
||||
|
||||
assert.deepStrictEqual(spread(1, [2, 3]), expected);
|
||||
assert.deepStrictEqual(spread(1, [2, 3], 4), expected);
|
||||
});
|
||||
|
||||
it('should treat `start` as `0` for negative or `NaN` values', function() {
|
||||
var values = [-1, NaN, 'a'],
|
||||
expected = lodashStable.map(values, lodashStable.constant([1, 2]));
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
var spread = _.spread(fn, value);
|
||||
return spread([1, 2]);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should coerce `start` to an integer', function() {
|
||||
var spread = _.spread(fn, 1.6),
|
||||
expected = [1, 2, 3];
|
||||
|
||||
assert.deepStrictEqual(spread(1, [2, 3]), expected);
|
||||
assert.deepStrictEqual(spread(1, [2, 3], 4), expected);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user