Skip to content

Commit 25a83eb

Browse files
JiaLiPassionAndrewKushnir
authored andcommitted
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
1 parent 955a677 commit 25a83eb

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

packages/zone.js/test/browser/browser.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,22 @@ describe('Zone', function() {
395395

396396
it('get window onerror should not throw error',
397397
ifEnvSupports(canPatchOnProperty(window, 'onerror'), function() {
398+
const oriOnError = window.onerror;
398399
const testFn = function() {
399-
let onerror = window.onerror;
400-
window.onerror = function() {};
401-
onerror = window.onerror;
400+
try {
401+
let onerror = window.onerror;
402+
window.onerror = function() {};
403+
onerror = window.onerror;
404+
} finally {
405+
window.onerror = oriOnError;
406+
}
402407
};
403408
expect(testFn).not.toThrow();
404409
}));
405410

406411
it('window.onerror callback signiture should be (message, source, lineno, colno, error)',
407412
ifEnvSupportsWithDone(canPatchOnProperty(window, 'onerror'), function(done: DoneFn) {
413+
const oriOnError = window.onerror;
408414
let testError = new Error('testError');
409415
window.onerror = function(
410416
message: any, source?: string, lineno?: number, colno?: number, error?: any) {
@@ -413,7 +419,7 @@ describe('Zone', function() {
413419
// Edge 14, error will be undefined.
414420
expect(error).toBe(testError);
415421
}
416-
(window as any).onerror = null;
422+
(window as any).onerror = oriOnError;
417423
setTimeout(done);
418424
return true;
419425
};

packages/zone.js/test/common/zone.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,23 @@ describe('Zone', function() {
334334
Zone.assertZonePatched();
335335
});
336336

337-
// xit('should throw error if ZoneAwarePromise has been overwritten', () => {
338-
// class WrongPromise {
339-
// static resolve(value: any) {}
340-
341-
// then() {}
342-
// }
343-
344-
// const ZoneAwarePromise = global.Promise;
345-
// try {
346-
// global.Promise = WrongPromise;
347-
// expect(Zone.assertZonePatched()).toThrow();
348-
// } finally {
349-
// // restore it.
350-
// global.Promise = ZoneAwarePromise;
351-
// }
352-
// Zone.assertZonePatched();
353-
// });
337+
it('should throw error if ZoneAwarePromise has been overwritten', () => {
338+
class WrongPromise {
339+
static resolve(value: any) {}
340+
341+
then() {}
342+
}
343+
344+
const ZoneAwarePromise = global.Promise;
345+
try {
346+
(global as any).Promise = WrongPromise;
347+
expect(() => Zone.assertZonePatched()).toThrow();
348+
} finally {
349+
// restore it.
350+
global.Promise = ZoneAwarePromise;
351+
}
352+
Zone.assertZonePatched();
353+
});
354354
});
355355
});
356356

0 commit comments

Comments
 (0)