Skip to content

Commit 91d7564

Browse files
committed
fix(http): remove axios config mutation
1 parent dc1bd46 commit 91d7564

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

packages/common/http/http.service.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ export class HttpService {
7373
...args: any[]
7474
) {
7575
return new Observable<AxiosResponse<T>>(subscriber => {
76-
let config: AxiosRequestConfig = args[args.length - 1];
77-
if (!config) {
78-
config = {};
79-
args[args.length - 1] = config;
80-
}
76+
const config = args[args.length - 1] ? { ...args[args.length - 1] } : {};
8177

8278
let cancelSource: CancelTokenSource;
8379
if (!config.cancelToken) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect } from 'chai';
2+
import { HttpService } from '../../http/http.service';
3+
import { AxiosRequestConfig, AxiosInstance } from 'axios';
4+
5+
describe('HttpService', () => {
6+
it('should not mutate user-given axios options object', () => {
7+
const http = new HttpService({ get: () => Promise.resolve() } as any);
8+
const options: AxiosRequestConfig = {};
9+
10+
http
11+
.get('/', options)
12+
.toPromise()
13+
.then(() => {
14+
expect(options.cancelToken).to.be.undefined;
15+
});
16+
});
17+
});

0 commit comments

Comments
 (0)