提交 68867fba 编写于 作者: M Matt Zabriskie

Merge pull request #106 from theverything/return-from-spread

return result from callback
......@@ -22,6 +22,6 @@
*/
module.exports = function spread(callback) {
return function (arr) {
callback.apply(null, arr);
return callback.apply(null, arr);
};
};
......@@ -9,5 +9,13 @@ describe('helpers::spread', function () {
expect(value).toEqual(50);
});
it('should return callback result', function () {
var value = spread(function (a, b) {
return a * b;
})([5, 10]);
expect(value).toEqual(50);
});
});
......@@ -54,15 +54,23 @@ describe('promise', function () {
it('should support spread', function (done) {
var sum = 0;
var fulfilled = false;
var result;
axios.all([123, 456]).then(axios.spread(function (a, b) {
sum = a + b;
fulfilled = true;
}));
axios
.all([123, 456])
.then(axios.spread(function (a, b) {
sum = a + b;
fulfilled = true;
return 'hello world';
}))
.then(function (res) {
result = res;
});
setTimeout(function () {
expect(fulfilled).toEqual(true);
expect(sum).toEqual(123 + 456);
expect(result).toEqual('hello world');
done();
}, 0);
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册