2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00
Files
axios/test/specs/instance.spec.js
T
Jay 76f09afc03 Release/v0.22.0 (#4107)
* fix/Avoid package.json import; (#4041)

* Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`;
Refactored `http.js` to use `env/data.js` instead of package.json;

* Added `env/data.js`;
Added `env/README.md`;

* Feat/export package version constant (#4065)

* Added auto-generated config module `env/data.js` for importing package environment vars without importing the whole `package.json`;
Refactored `http.js` to use `env/data.js` instead of package.json;

* Added `env/data.js`;
Added `env/README.md`;

* Export package version constant;

* Fixed cancelToken leakage; Added AbortController support; (#3305)

* Fixed cancelToken leakage;
Added AbortController support;

* Fixed typings;

* Documented `signal` option;

* Added processing of early cancellation using AbortController without sending a request;

Co-authored-by: Jay <jasonsaayman@gmail.com>

* Updating CI to run on release branches

* Fixed default transitional config for custom Axios instance; (#4052)

Refactored `/core/mergeConfig`;

Co-authored-by: Jay <jasonsaayman@gmail.com>

* Prepping v0.22.0 for release

* Updated date

Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
2021-10-01 08:02:13 +02:00

116 lines
2.6 KiB
JavaScript

describe('instance', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should have the same methods as default instance', function () {
var instance = axios.create();
for (var prop in axios) {
if ([
'Axios',
'create',
'Cancel',
'CancelToken',
'isCancel',
'all',
'spread',
'isAxiosError',
'VERSION',
'default'].indexOf(prop) > -1) {
continue;
}
expect(typeof instance[prop]).toBe(typeof axios[prop]);
}
});
it('should make an http request without verb helper', function (done) {
var instance = axios.create();
instance('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
done();
});
});
it('should make an http request with url instead of baseURL', function (done) {
var instance = axios.create({
url: 'https://api.example.com'
});
instance('/foo');
getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo');
done();
});
});
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 defaults.headers', function () {
var instance = axios.create({
baseURL: 'https://api.example.com'
});
expect(typeof instance.defaults.headers, 'object');
expect(typeof instance.defaults.headers.common, 'object');
});
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();
}, 100);
});
});
});