diff --git a/lib/webResource.ts b/lib/webResource.ts index 92a925a..c5890b2 100644 --- a/lib/webResource.ts +++ b/lib/webResource.ts @@ -298,7 +298,7 @@ export interface RequestPrepareOptions { deserializationMapper?: object; disableJsonStringifyOnBody?: boolean; bodyIsStream?: boolean; - cancellationToken: CancellationTokenLike; + cancellationToken?: CancellationTokenLike; } /** diff --git a/test/shared/axiosHttpClientTests.ts b/test/shared/axiosHttpClientTests.ts index 96d8679..6605534 100644 --- a/test/shared/axiosHttpClientTests.ts +++ b/test/shared/axiosHttpClientTests.ts @@ -98,13 +98,16 @@ describe("axiosHttpClient", () => { }); }); - it("should allow canceling requests", async () => { + it("should allow canceling requests", async function() { + // ensure that a large upload is actually cancelled + this.timeout(200); + const cancellationToken: CancellationTokenLike = { - setCancellationListener: function(listener){ this.cancel = listener }, + setCancellationListener: (listener) => { cancellationToken.cancel = listener }, cancel: () => {} }; - const request = new WebResource(`{baseURL}/httpbin-index.html`, "GET", undefined, undefined, undefined, false, cancellationToken); + const request = new WebResource(`${baseURL}/fileupload`, "POST", new Uint8Array(1024*1024*100), undefined, undefined, true, cancellationToken); const client = new AxiosHttpClient(); const promise = client.sendRequest(request); cancellationToken.cancel();