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

Commit

Permalink
fix(patch): patchOnProperty getter should return original listener
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Aug 25, 2017
1 parent b9c0d9c commit 7dc5c1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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
22 changes: 21 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,24 @@ 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 listener = req.onreadystatechange = function() {
if (req.readyState === 4) {
done();
}
};
expect(req.onreadystatechange).toBe(listener);
req.onreadystatechange = function() {
return listener.apply(this, arguments);
};
req.send();
});
}));
});

0 comments on commit 7dc5c1b

Please sign in to comment.