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

Initial interceptor implementation.

This commit is contained in:
Jason Dobry
2014-12-02 15:45:19 -07:00
parent d93df704a2
commit 5bb39f3279
8 changed files with 680 additions and 168 deletions
+39 -27
View File
@@ -3,27 +3,36 @@ describe('promise', function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should provide succinct object to then', function () {
var response;
var fulfilled = false;
var request, response;
axios({
url: '/foo'
}).then(function (r) {
runs(function () {
axios({
url: '/foo'
}).then(function (r) {
response = r;
fulfilled = true;
});
var request = jasmine.Ajax.requests.mostRecent();
request.response({
status: 200,
responseText: '{"hello":"world"}'
});
waitsFor(function () {
return fulfilled;
return request = jasmine.Ajax.requests.mostRecent();
}, 'waiting for the request', 100);
runs(function () {
request.response({
status: 200,
responseText: '{"hello":"world"}'
});
});
waitsFor(function () {
return response;
}, 'waiting for the response', 100);
runs(function () {
expect(typeof response).toEqual('object');
expect(response.data.hello).toEqual('world');
@@ -34,32 +43,35 @@ describe('promise', function () {
});
it('should provide verbose arguments to success', function () {
var data;
var status;
var headers;
var config;
var fulfilled = false;
var request, data, status, headers, config;
axios({
url: '/foo'
}).success(function (d, s, h, c) {
runs(function () {
axios({
url: '/foo'
}).success(function (d, s, h, c) {
data = d;
status = s;
headers = h;
config = c;
fulfilled = true;
});
var request = jasmine.Ajax.requests.mostRecent();
request.response({
status: 200,
responseText: '{"hello":"world"}'
});
waitsFor(function () {
return fulfilled;
return request = jasmine.Ajax.requests.mostRecent();
}, 'waiting for the request', 100);
runs(function () {
request.response({
status: 200,
responseText: '{"hello":"world"}'
});
});
waitsFor(function () {
return data;
}, 'waiting for the data', 100);
runs(function () {
expect(data.hello).toEqual('world');
expect(status).toBe(200);
@@ -102,4 +114,4 @@ describe('promise', function () {
expect(sum).toEqual(123 + 456);
});
});
});
});