2
0
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:
Nick Uraltsev
2016-09-17 11:52:56 -07:00
parent df50698d5a
commit 72dd897bb5
7 changed files with 139 additions and 10 deletions
+16
View File
@@ -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();
});
});
}
};