fix(zone.js): update several flaky cases (#41526)

Related to #41434

Fix several flaky cases.

1. should restore `window.onerror` in test cases.
2. expect().toThrow() should pass a function.

PR Close #41526
This commit is contained in:
JiaLiPassion
2021-04-09 07:05:52 +08:00
committed by Andrew Kushnir
parent 955a677aab
commit 25a83eb264
2 changed files with 25 additions and 19 deletions
+10 -4
View File
@@ -395,16 +395,22 @@ describe('Zone', function() {
it('get window onerror should not throw error',
ifEnvSupports(canPatchOnProperty(window, 'onerror'), function() {
const oriOnError = window.onerror;
const testFn = function() {
let onerror = window.onerror;
window.onerror = function() {};
onerror = window.onerror;
try {
let onerror = window.onerror;
window.onerror = function() {};
onerror = window.onerror;
} finally {
window.onerror = oriOnError;
}
};
expect(testFn).not.toThrow();
}));
it('window.onerror callback signiture should be (message, source, lineno, colno, error)',
ifEnvSupportsWithDone(canPatchOnProperty(window, 'onerror'), function(done: DoneFn) {
const oriOnError = window.onerror;
let testError = new Error('testError');
window.onerror = function(
message: any, source?: string, lineno?: number, colno?: number, error?: any) {
@@ -413,7 +419,7 @@ describe('Zone', function() {
// Edge 14, error will be undefined.
expect(error).toBe(testError);
}
(window as any).onerror = null;
(window as any).onerror = oriOnError;
setTimeout(done);
return true;
};
+15 -15
View File
@@ -334,23 +334,23 @@ describe('Zone', function() {
Zone.assertZonePatched();
});
// xit('should throw error if ZoneAwarePromise has been overwritten', () => {
// class WrongPromise {
// static resolve(value: any) {}
it('should throw error if ZoneAwarePromise has been overwritten', () => {
class WrongPromise {
static resolve(value: any) {}
// then() {}
// }
then() {}
}
// const ZoneAwarePromise = global.Promise;
// try {
// global.Promise = WrongPromise;
// expect(Zone.assertZonePatched()).toThrow();
// } finally {
// // restore it.
// global.Promise = ZoneAwarePromise;
// }
// Zone.assertZonePatched();
// });
const ZoneAwarePromise = global.Promise;
try {
(global as any).Promise = WrongPromise;
expect(() => Zone.assertZonePatched()).toThrow();
} finally {
// restore it.
global.Promise = ZoneAwarePromise;
}
Zone.assertZonePatched();
});
});
});