Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit b91f8fe

Browse files
committed
fix(PatchClass): copy static properties
fixes #127
1 parent 08c7084 commit b91f8fe

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ function patchClass(className) {
146146
});
147147
}
148148
}(prop));
149-
};
149+
}
150+
151+
for (prop in OriginalClass) {
152+
if (prop !== 'prototype' && OriginalClass.hasOwnProperty(prop)) {
153+
global[className][prop] = OriginalClass[prop];
154+
}
155+
}
150156
};
151157

152158
module.exports = {

test/patch/XMLHttpRequest.spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ describe('XMLHttpRequest', function () {
2121
req.send();
2222
});
2323

24-
var supportsOnProgress = function() {
24+
var supportsOnProgress = function() {
2525
return 'onprogress' in new XMLHttpRequest();
2626
}
2727
supportsOnProgress.message = "XMLHttpRequest.onprogress";
28-
28+
2929
describe('onprogress', ifEnvSupports(supportsOnProgress, function () {
3030
it('should work with onprogress', function (done) {
3131
var req;
@@ -52,5 +52,12 @@ describe('XMLHttpRequest', function () {
5252
expect(req.responseType).toBe('document');
5353
});
5454

55+
it('should preserve static constants', function() {
56+
expect(XMLHttpRequest.UNSENT).toEqual(0);
57+
expect(XMLHttpRequest.OPENED).toEqual(1);
58+
expect(XMLHttpRequest.HEADERS_RECEIVED).toEqual(2);
59+
expect(XMLHttpRequest.LOADING).toEqual(3);
60+
expect(XMLHttpRequest.DONE).toEqual(4);
61+
});
5562
});
5663

0 commit comments

Comments
 (0)