2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

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

return result from callback
This commit is contained in:
Matt Zabriskie
2015-09-21 16:45:17 -06:00
3 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -22,6 +22,6 @@
*/
module.exports = function spread(callback) {
return function (arr) {
callback.apply(null, arr);
return callback.apply(null, arr);
};
};
+8
View File
@@ -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);
});
});
+12 -4
View File
@@ -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);
});