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

fix(patch): fix #886, #885, patchOnProperties getter should return original listener. #887

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ export function patchProperty(obj: any, prop: string, prototype?: any) {
if (!target) {
return null;
}
if (target[eventNameSymbol]) {
return wrapFn;
const listener = target[eventNameSymbol];
if (listener) {
return listener;
} else if (originalDescGet) {
// result will be null when use inline event attribute,
// such as <button onclick="func();">OK</button>
Expand Down
25 changes: 24 additions & 1 deletion test/browser/XMLHttpRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ifEnvSupports, supportPatchXHROnProperty} from '../test-util';
import {ifEnvSupports, ifEnvSupportsWithDone, supportPatchXHROnProperty} from '../test-util';

describe('XMLHttpRequest', function() {
let testZone: Zone;
Expand Down Expand Up @@ -280,4 +280,27 @@ describe('XMLHttpRequest', function() {
req.send();
});
});

it('should return origin listener when call xhr.onreadystatechange',
ifEnvSupportsWithDone(supportPatchXHROnProperty, function(done: Function) {
testZone.run(function() {
// sometimes this case will cause timeout
// so we set it longer
const req = new XMLHttpRequest();
req.open('get', '/', true);
const interval = (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL;
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 5000;
const listener = req.onreadystatechange = function() {
if (req.readyState === 4) {
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = interval;
done();
}
};
expect(req.onreadystatechange).toBe(listener);
req.onreadystatechange = function() {
return listener.apply(this, arguments);
};
req.send();
});
}));
});