2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

Adding support for removing interceptors

This commit is contained in:
mzabriskie
2015-01-23 01:32:54 -07:00
parent 7b05902b3c
commit 9e3830cf92
3 changed files with 110 additions and 24 deletions
+46
View File
@@ -296,4 +296,50 @@ describe('interceptors', function () {
expect(response.data).toBe('OK123');
});
});
it('should allow removing interceptors', function () {
var request, response, intercept;
runs(function () {
axios.interceptors.response.use(function (data) {
data.data = data.data + '1';
return data;
});
intercept = axios.interceptors.response.use(function (data) {
data.data = data.data + '2';
return data;
});
axios.interceptors.response.use(function (data) {
data.data = data.data + '3';
return data;
});
axios.interceptors.response.eject(intercept);
axios({
url: '/foo'
}).then(function (data) {
response = data;
});
});
waitsFor(function () {
return request = jasmine.Ajax.requests.mostRecent();
}, 'waiting for the request', 100);
runs(function () {
request.response({
status: 200,
responseText: 'OK'
});
});
waitsFor(function () {
return response;
}, 'waiting for the response', 100);
runs(function () {
expect(response.data).toBe('OK13');
});
});
});