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:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user