mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add _.spread.
This commit is contained in:
committed by
jdalton
parent
ba4da24984
commit
e91a662491
50
test/test.js
50
test/test.js
@@ -12240,6 +12240,53 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.spread');
|
||||
|
||||
(function() {
|
||||
function Pair(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
return 42;
|
||||
}
|
||||
|
||||
function divide(n, d) {
|
||||
return n / d;
|
||||
}
|
||||
|
||||
test('should pass arguments to `func`', 1, function() {
|
||||
var spread = _.spread(divide);
|
||||
strictEqual(spread([4, 2]), 2);
|
||||
});
|
||||
|
||||
test('should fail when receiving non-array argument', 1, function() {
|
||||
var spread = _.spread(divide);
|
||||
var err;
|
||||
try {
|
||||
spread(4, 2);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
strictEqual(_.isError(err), true);
|
||||
});
|
||||
|
||||
test('should dynamically `func` to `thisArg`', 2, function() {
|
||||
var self = {z: 3};
|
||||
var spread = _.spread(Pair, self);
|
||||
var result = spread([1, 2]);
|
||||
strictEqual(result, 42);
|
||||
deepEqual(self, {x: 1, y: 2, z: 3});
|
||||
});
|
||||
|
||||
test('should use `undefined` for extra values', 1, function() {
|
||||
var self = {};
|
||||
_.spread(Pair, self)([1]);
|
||||
deepEqual(self, {x: 1, y: undefined});
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.support');
|
||||
|
||||
(function() {
|
||||
@@ -14960,6 +15007,7 @@
|
||||
'partial',
|
||||
'partialRight',
|
||||
'rearg',
|
||||
'spread',
|
||||
'throttle'
|
||||
];
|
||||
|
||||
@@ -15078,7 +15126,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
test('should throw an error for falsey arguments', 22, function() {
|
||||
test('should throw an error for falsey arguments', 23, function() {
|
||||
_.each(rejectFalsey, function(methodName) {
|
||||
var expected = _.map(falsey, _.constant(true)),
|
||||
func = _[methodName];
|
||||
|
||||
Reference in New Issue
Block a user