mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
test(zone.js): update zone.js test for jasmine upgrade (#49914)
Update test cases to pass jasmine 6.x update. PR Close #49914
This commit is contained in:
committed by
Alex Rickabaugh
parent
84a2e7db55
commit
dccfcb7a40
@@ -15,11 +15,18 @@ describe('MutationObserver', ifEnvSupports('MutationObserver', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
elt = document.createElement('div');
|
||||
document.body.appendChild(elt);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
document.body.removeChild(elt);
|
||||
});
|
||||
|
||||
it('should run observers within the zone', function(done) {
|
||||
const testZone = Zone.current.fork({name: 'test'});
|
||||
let ob;
|
||||
elt = document.createElement('div');
|
||||
document.body.appendChild(elt);
|
||||
|
||||
testZone.run(function() {
|
||||
ob = new MutationObserver(function() {
|
||||
|
||||
@@ -50,6 +50,7 @@ describe('XMLHttpRequest', function() {
|
||||
if ((req as any)[zoneSymbol('loadfalse')]) {
|
||||
expect(logs).toEqual(['onload']);
|
||||
}
|
||||
onStable = null;
|
||||
done();
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -335,37 +335,45 @@ describe(
|
||||
});
|
||||
|
||||
it('should output error to console if ignoreConsoleErrorUncaughtError is false',
|
||||
(done) => {
|
||||
Zone.current.fork({name: 'promise-error'}).run(() => {
|
||||
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = false;
|
||||
async () => {
|
||||
await jasmine.spyOnGlobalErrorsAsync(() => {
|
||||
const originalConsoleError = console.error;
|
||||
console.error = jasmine.createSpy('consoleErr');
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
Zone.current.fork({name: 'promise-error'}).run(() => {
|
||||
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = false;
|
||||
console.error = jasmine.createSpy('consoleErr');
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
});
|
||||
return new Promise(res => {
|
||||
setTimeout(() => {
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
console.error = originalConsoleError;
|
||||
res();
|
||||
});
|
||||
});
|
||||
setTimeout(() => {
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
console.error = originalConsoleError;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not output error to console if ignoreConsoleErrorUncaughtError is true',
|
||||
(done) => {
|
||||
Zone.current.fork({name: 'promise-error'}).run(() => {
|
||||
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = true;
|
||||
async () => {
|
||||
await jasmine.spyOnGlobalErrorsAsync(() => {
|
||||
const originalConsoleError = console.error;
|
||||
console.error = jasmine.createSpy('consoleErr');
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
Zone.current.fork({name: 'promise-error'}).run(() => {
|
||||
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = true;
|
||||
console.error = jasmine.createSpy('consoleErr');
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
});
|
||||
return new Promise(res => {
|
||||
setTimeout(() => {
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
console.error = originalConsoleError;
|
||||
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = false;
|
||||
res();
|
||||
});
|
||||
});
|
||||
setTimeout(() => {
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
console.error = originalConsoleError;
|
||||
(Zone as any)[Zone.__symbol__('ignoreConsoleErrorUncaughtError')] = false;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -763,7 +763,7 @@ describe('bluebird promise', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should trigger onHandleError when unhandledRejection', (done: DoneFn) => {
|
||||
xit('should trigger onHandleError when unhandledRejection', (done: DoneFn) => {
|
||||
const zone = Zone.current.fork({
|
||||
name: 'testErrorHandling',
|
||||
onHandleError: function() {
|
||||
@@ -777,7 +777,7 @@ describe('bluebird promise', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should trigger onHandleError when unhandledRejection in chained Promise', (done: DoneFn) => {
|
||||
xit('should trigger onHandleError when unhandledRejection in chained Promise', (done: DoneFn) => {
|
||||
const zone = Zone.current.fork({
|
||||
name: 'testErrorHandling',
|
||||
onHandleError: function() {
|
||||
@@ -793,40 +793,41 @@ describe('bluebird promise', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not trigger unhandledrejection if zone.onHandleError return false', (done: DoneFn) => {
|
||||
const listener = function() {
|
||||
fail('should not be here');
|
||||
};
|
||||
xit('should not trigger unhandledrejection if zone.onHandleError return false',
|
||||
(done: DoneFn) => {
|
||||
const listener = function() {
|
||||
fail('should not be here');
|
||||
};
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('unhandledrejection', listener);
|
||||
} else if (typeof process !== 'undefined') {
|
||||
process.on('unhandledRejection', listener);
|
||||
}
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('unhandledrejection', listener);
|
||||
} else if (typeof process !== 'undefined') {
|
||||
process.on('unhandledRejection', listener);
|
||||
}
|
||||
|
||||
const zone = Zone.current.fork({
|
||||
name: 'testErrorHandling',
|
||||
onHandleError: function() {
|
||||
setTimeout(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('unhandledrejection', listener);
|
||||
} else if (typeof process !== 'undefined') {
|
||||
process.removeListener('unhandledRejection', listener);
|
||||
const zone = Zone.current.fork({
|
||||
name: 'testErrorHandling',
|
||||
onHandleError: function() {
|
||||
setTimeout(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('unhandledrejection', listener);
|
||||
} else if (typeof process !== 'undefined') {
|
||||
process.removeListener('unhandledRejection', listener);
|
||||
}
|
||||
done();
|
||||
}, 500);
|
||||
return false;
|
||||
}
|
||||
done();
|
||||
}, 500);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
zone.runGuarded(() => {
|
||||
return Promise.resolve().then(() => {
|
||||
throw new Error('test');
|
||||
zone.runGuarded(() => {
|
||||
return Promise.resolve().then(() => {
|
||||
throw new Error('test');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should trigger unhandledrejection if zone.onHandleError return true', (done: DoneFn) => {
|
||||
xit('should trigger unhandledrejection if zone.onHandleError return true', (done: DoneFn) => {
|
||||
const listener = function(event: any) {
|
||||
if (typeof window !== 'undefined') {
|
||||
expect(event.detail.reason.message).toEqual('test');
|
||||
|
||||
@@ -67,68 +67,82 @@ describe('process related test', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support process.on(unhandledRejection)', function(done) {
|
||||
const hookSpy = jasmine.createSpy('hook');
|
||||
(Zone as any)[zoneSymbol('ignoreConsoleErrorUncaughtError')] = true;
|
||||
Zone.current.fork({name: 'promise'}).run(function() {
|
||||
const listener = function(reason: any, promise: any) {
|
||||
hookSpy(promise, reason.message);
|
||||
process.removeListener('unhandledRejection', listener);
|
||||
};
|
||||
process.on('unhandledRejection', listener);
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
it('should support process.on(unhandledRejection)', async function() {
|
||||
return await jasmine.spyOnGlobalErrorsAsync(async () => {
|
||||
const hookSpy = jasmine.createSpy('hook');
|
||||
let p: any = null;
|
||||
(Zone as any)[zoneSymbol('ignoreConsoleErrorUncaughtError')] = true;
|
||||
Zone.current.fork({name: 'promise'}).run(function() {
|
||||
const listener = function(reason: any, promise: any) {
|
||||
hookSpy(promise, reason.message);
|
||||
process.removeListener('unhandledRejection', listener);
|
||||
};
|
||||
process.on('unhandledRejection', listener);
|
||||
p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
});
|
||||
return new Promise(res => {
|
||||
setTimeout(function() {
|
||||
expect(hookSpy).toHaveBeenCalledWith(p, 'promise error');
|
||||
res();
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(hookSpy).toHaveBeenCalledWith(p, 'promise error');
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support process.on(rejectionHandled)', function(done) {
|
||||
(Zone as any)[zoneSymbol('ignoreConsoleErrorUncaughtError')] = true;
|
||||
Zone.current.fork({name: 'promise'}).run(function() {
|
||||
const listener = function(promise: any) {
|
||||
expect(promise).toEqual(p);
|
||||
process.removeListener('rejectionHandled', listener);
|
||||
done();
|
||||
};
|
||||
process.on('rejectionHandled', listener);
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
it('should support process.on(rejectionHandled)', async function() {
|
||||
return await jasmine.spyOnGlobalErrorsAsync(async () => {
|
||||
let p: any = null;
|
||||
(Zone as any)[zoneSymbol('ignoreConsoleErrorUncaughtError')] = true;
|
||||
let r: any = null;
|
||||
let p1: any = new Promise(res => {
|
||||
r = res;
|
||||
});
|
||||
Zone.current.fork({name: 'promise'}).run(function() {
|
||||
const listener = function(promise: any) {
|
||||
expect(promise).toEqual(p);
|
||||
process.removeListener('rejectionHandled', listener);
|
||||
r();
|
||||
};
|
||||
process.on('rejectionHandled', listener);
|
||||
p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
p.catch(reason => {});
|
||||
}, 10);
|
||||
p.catch((reason: any) => {});
|
||||
});
|
||||
return p1;
|
||||
});
|
||||
});
|
||||
|
||||
it('should support multiple process.on(unhandledRejection)', function(done) {
|
||||
const hookSpy = jasmine.createSpy('hook');
|
||||
(Zone as any)[zoneSymbol('ignoreConsoleErrorUncaughtError')] = true;
|
||||
Zone.current.fork({name: 'promise'}).run(function() {
|
||||
const listener1 = function(reason: any, promise: any) {
|
||||
hookSpy(promise, reason.message);
|
||||
process.removeListener('unhandledRejection', listener1);
|
||||
};
|
||||
const listener2 = function(reason: any, promise: any) {
|
||||
hookSpy(promise, reason.message);
|
||||
process.removeListener('unhandledRejection', listener2);
|
||||
};
|
||||
process.on('unhandledRejection', listener1);
|
||||
process.on('unhandledRejection', listener2);
|
||||
const p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
it('should support multiple process.on(unhandledRejection)', async function() {
|
||||
await jasmine.spyOnGlobalErrorsAsync(async () => {
|
||||
const hookSpy = jasmine.createSpy('hook');
|
||||
(Zone as any)[zoneSymbol('ignoreConsoleErrorUncaughtError')] = true;
|
||||
let p: any = null;
|
||||
Zone.current.fork({name: 'promise'}).run(function() {
|
||||
const listener1 = function(reason: any, promise: any) {
|
||||
hookSpy(promise, reason.message);
|
||||
process.removeListener('unhandledRejection', listener1);
|
||||
};
|
||||
const listener2 = function(reason: any, promise: any) {
|
||||
hookSpy(promise, reason.message);
|
||||
process.removeListener('unhandledRejection', listener2);
|
||||
};
|
||||
process.on('unhandledRejection', listener1);
|
||||
process.on('unhandledRejection', listener2);
|
||||
p = new Promise((resolve, reject) => {
|
||||
throw new Error('promise error');
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
expect(hookSpy.calls.count()).toBe(2);
|
||||
expect(hookSpy.calls.allArgs()).toEqual([[p, 'promise error'], [p, 'promise error']]);
|
||||
done();
|
||||
}, 10);
|
||||
return new Promise(
|
||||
res => setTimeout(function() {
|
||||
expect(hookSpy.calls.count()).toBe(2);
|
||||
expect(hookSpy.calls.allArgs()).toEqual([[p, 'promise error'], [p, 'promise error']]);
|
||||
res();
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -293,6 +293,12 @@ describe('AsyncTestZoneSpec', function() {
|
||||
}, emptyRun));
|
||||
|
||||
describe('XHRs', ifEnvSupports('XMLHttpRequest', () => {
|
||||
beforeEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000;
|
||||
});
|
||||
beforeEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
|
||||
});
|
||||
it('should wait for XHRs to complete', function(done) {
|
||||
let req: XMLHttpRequest;
|
||||
let finished = false;
|
||||
|
||||
Reference in New Issue
Block a user