mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
var axios = require('../../index');
|
|
var getAjaxRequest = require('./__getAjaxRequest');
|
|
|
|
describe('instance', function () {
|
|
beforeEach(function () {
|
|
jasmine.Ajax.install();
|
|
});
|
|
|
|
afterEach(function () {
|
|
jasmine.Ajax.uninstall();
|
|
});
|
|
|
|
it('should make an http request', function (done) {
|
|
var instance = axios.create();
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
expect(request.url).toBe('/foo');
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should use instance options', function (done) {
|
|
var instance = axios.create({ timeout: 1000 });
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
expect(request.timeout).toBe(1000);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should have interceptors on the instance', function (done) {
|
|
axios.interceptors.request.use(function (config) {
|
|
config.foo = true;
|
|
return config;
|
|
});
|
|
|
|
var instance = axios.create();
|
|
instance.interceptors.request.use(function (config) {
|
|
config.bar = true;
|
|
return config;
|
|
});
|
|
|
|
var response;
|
|
instance.get('/foo').then(function (res) {
|
|
response = res;
|
|
});
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
request.respondWith({
|
|
status: 200
|
|
});
|
|
|
|
setTimeout(function () {
|
|
expect(response.config.foo).toEqual(undefined);
|
|
expect(response.config.bar).toEqual(true);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|