mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Adding cancellation support
This commit is contained in:
@@ -320,5 +320,21 @@ module.exports = {
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testCancel: function(test) {
|
||||
var source = axios.CancelToken.source();
|
||||
server = http.createServer(function (req, res) {
|
||||
// call cancel() when the request has been sent, but a response has not been received
|
||||
source.cancel('Operation has been canceled.');
|
||||
}).listen(4444, function() {
|
||||
axios.get('http://localhost:4444/', {
|
||||
cancelToken: source.token
|
||||
}).catch(function (thrown) {
|
||||
test.ok(thrown instanceof axios.Cancel, 'Promise must be rejected with a Cancel obejct');
|
||||
test.equal(thrown.message, 'Operation has been canceled.');
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user