Skip to content

Commit

Permalink
feat(ajax-helper): update MockXMLHttpRequest upload property behavior
Browse files Browse the repository at this point in the history
Observable.ajax would set xhr.upload.onprogress when progressSubscriber is not empty. And if xhr.upload.onprogress was set after xhr.open, it would not be fired. So ajax-helper should initial an empty upload object, and freeze the setter after open method called.
  • Loading branch information
Brooooooklyn committed Dec 19, 2016
1 parent dc06e01 commit 45a611a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion spec/helpers/ajax-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class MockXMLHttpRequest {
onerror: (e: ErrorEvent) => any;
onprogress: (e: ProgressEvent) => any;
ontimeout: (e: ProgressEvent) => any;
upload: XMLHttpRequestUpload;
upload: XMLHttpRequestUpload = Object.create(null);

constructor() {
this.previousRequest = MockXMLHttpRequest.recentRequest;
Expand All @@ -158,6 +158,12 @@ export class MockXMLHttpRequest {
this.password = password;
this.readyState = 1;
this.triggerEvent('readyStateChange');
const originalProgressHandler = this.upload.onprogress;
Object.defineProperty(this.upload, 'progress', {
get() {
return originalProgressHandler;
}
});
}

setRequestHeader(key: any, value: any): void {
Expand Down

0 comments on commit 45a611a

Please sign in to comment.