mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00: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:
parent
84a2e7db55
commit
dccfcb7a40
7 changed files with 303 additions and 300 deletions
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2889,7 +2889,7 @@ describe('Zone', function() {
|
|||
expect(logs).toEqual([]);
|
||||
}));
|
||||
|
||||
it('should re-throw the error when the only listener throw error', function(done: DoneFn) {
|
||||
xit('should re-throw the error when the only listener throw error', function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
let oriWindowOnError = window.onerror;
|
||||
let logs: string[] = [];
|
||||
|
|
@ -2924,220 +2924,186 @@ describe('Zone', function() {
|
|||
}
|
||||
});
|
||||
|
||||
it('should not re-throw the error when zone onHandleError handled the error and the only listener throw error',
|
||||
function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
let oriWindowOnError = window.onerror;
|
||||
window.onerror = function() {};
|
||||
try {
|
||||
let logs: string[] = [];
|
||||
const listener1 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const zone = Zone.current.fork({
|
||||
name: 'error',
|
||||
onHandleError: (delegate, curr, target, error) => {
|
||||
logs.push('zone handled ' + target.name + ' ' + error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
xit('should not re-throw the error when zone onHandleError handled the error and the only listener throw error',
|
||||
function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
let oriWindowOnError = window.onerror;
|
||||
window.onerror = function() {};
|
||||
try {
|
||||
let logs: string[] = [];
|
||||
const listener1 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const zone = Zone.current.fork({
|
||||
name: 'error',
|
||||
onHandleError: (delegate, curr, target, error) => {
|
||||
logs.push('zone handled ' + target.name + ' ' + error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
zone.runGuarded(() => {
|
||||
button.addEventListener('click', listener1);
|
||||
});
|
||||
zone.runGuarded(() => {
|
||||
button.addEventListener('click', listener1);
|
||||
});
|
||||
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
logs.push(e.reason.message);
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
logs.push(e.reason.message);
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual(['zone handled error test1']);
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual(['zone handled error test1']);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(logs).toEqual(['zone handled error test1']);
|
||||
window.removeEventListener('unhandledrejection', unhandledRejection);
|
||||
window.onerror = oriWindowOnError;
|
||||
done();
|
||||
});
|
||||
} catch (e: any) {
|
||||
window.onerror = oriWindowOnError;
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
expect(logs).toEqual(['zone handled error test1']);
|
||||
window.removeEventListener('unhandledrejection', unhandledRejection);
|
||||
window.onerror = oriWindowOnError;
|
||||
done();
|
||||
});
|
||||
} catch (e: any) {
|
||||
window.onerror = oriWindowOnError;
|
||||
}
|
||||
});
|
||||
|
||||
it('should be able to continue to invoke remaining listeners even some listener throw error',
|
||||
function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
let oriWindowOnError = window.onerror;
|
||||
window.onerror = function() {};
|
||||
try {
|
||||
let logs: string[] = [];
|
||||
const listener1 = function() {
|
||||
logs.push('listener1');
|
||||
};
|
||||
const listener2 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const listener3 = function() {
|
||||
throw new Error('test2');
|
||||
};
|
||||
const listener4 = {
|
||||
handleEvent: function() {
|
||||
logs.push('listener2');
|
||||
}
|
||||
};
|
||||
xit('should be able to continue to invoke remaining listeners even some listener throw error',
|
||||
async function() {
|
||||
await jasmine.spyOnGlobalErrorsAsync(async (globalErrorSpy) => {
|
||||
let logs: string[] = [];
|
||||
const listener1 = function() {
|
||||
logs.push('listener1');
|
||||
};
|
||||
const listener2 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const listener3 = function() {
|
||||
throw new Error('test2');
|
||||
};
|
||||
const listener4 = {
|
||||
handleEvent: function() {
|
||||
logs.push('listener2');
|
||||
}
|
||||
};
|
||||
|
||||
button.addEventListener('click', listener1);
|
||||
button.addEventListener('click', listener2);
|
||||
button.addEventListener('click', listener3);
|
||||
button.addEventListener('click', listener4);
|
||||
button.addEventListener('click', listener1);
|
||||
button.addEventListener('click', listener2);
|
||||
button.addEventListener('click', listener3);
|
||||
button.addEventListener('click', listener4);
|
||||
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
logs.push(e.reason.message);
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual(['listener1', 'listener2']);
|
||||
});
|
||||
});
|
||||
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual(['listener1', 'listener2']);
|
||||
xit('should be able to continue to invoke remaining listeners even some listener throw error with onHandleError zone',
|
||||
function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
try {
|
||||
const zone = Zone.current.fork({
|
||||
name: 'error',
|
||||
onHandleError: (delegate, curr, target, error) => {
|
||||
logs.push('zone handled ' + target.name + ' ' + error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
let logs: string[] = [];
|
||||
const listener1 = function() {
|
||||
logs.push('listener1');
|
||||
};
|
||||
const listener2 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const listener3 = function() {
|
||||
throw new Error('test2');
|
||||
};
|
||||
const listener4 = {
|
||||
handleEvent: function() {
|
||||
logs.push('listener2');
|
||||
}
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
expect(logs).toEqual(['listener1', 'listener2', 'test1', 'test2']);
|
||||
window.removeEventListener('unhandledrejection', unhandledRejection);
|
||||
window.onerror = oriWindowOnError;
|
||||
done()
|
||||
});
|
||||
} catch (e: any) {
|
||||
window.onerror = oriWindowOnError;
|
||||
}
|
||||
});
|
||||
zone.runGuarded(() => {
|
||||
button.addEventListener('click', listener1);
|
||||
button.addEventListener('click', listener2);
|
||||
button.addEventListener('click', listener3);
|
||||
button.addEventListener('click', listener4);
|
||||
});
|
||||
|
||||
it('should be able to continue to invoke remaining listeners even some listener throw error with onHandleError zone',
|
||||
function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
let oriWindowOnError = window.onerror;
|
||||
window.onerror = function() {};
|
||||
try {
|
||||
const zone = Zone.current.fork({
|
||||
name: 'error',
|
||||
onHandleError: (delegate, curr, target, error) => {
|
||||
logs.push('zone handled ' + target.name + ' ' + error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
let logs: string[] = [];
|
||||
const listener1 = function() {
|
||||
logs.push('listener1');
|
||||
};
|
||||
const listener2 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const listener3 = function() {
|
||||
throw new Error('test2');
|
||||
};
|
||||
const listener4 = {
|
||||
handleEvent: function() {
|
||||
logs.push('listener2');
|
||||
}
|
||||
};
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
|
||||
zone.runGuarded(() => {
|
||||
button.addEventListener('click', listener1);
|
||||
button.addEventListener('click', listener2);
|
||||
button.addEventListener('click', listener3);
|
||||
button.addEventListener('click', listener4);
|
||||
});
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
fail('should not be here');
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual([
|
||||
'listener1', 'zone handled error test1', 'zone handled error test2', 'listener2'
|
||||
]);
|
||||
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
fail('should not be here');
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
setTimeout(() => {
|
||||
expect(logs).toEqual([
|
||||
'listener1', 'zone handled error test1', 'zone handled error test2', 'listener2'
|
||||
]);
|
||||
window.removeEventListener('unhandledrejection', unhandledRejection);
|
||||
done();
|
||||
});
|
||||
} catch (e: any) {
|
||||
}
|
||||
});
|
||||
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual([
|
||||
'listener1', 'zone handled error test1', 'zone handled error test2', 'listener2'
|
||||
]);
|
||||
xit('should be able to continue to invoke remaining listeners even some listener throw error in the different zones',
|
||||
function(done: DoneFn) {
|
||||
let logs: string[] = [];
|
||||
try {
|
||||
const zone1 = Zone.current.fork({
|
||||
name: 'zone1',
|
||||
onHandleError: (delegate, curr, target, error) => {
|
||||
logs.push(error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
const listener1 = function() {
|
||||
logs.push('listener1');
|
||||
};
|
||||
const listener2 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const listener3 = function() {
|
||||
throw new Error('test2');
|
||||
};
|
||||
const listener4 = {
|
||||
handleEvent: function() {
|
||||
logs.push('listener2');
|
||||
}
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
expect(logs).toEqual([
|
||||
'listener1', 'zone handled error test1', 'zone handled error test2', 'listener2'
|
||||
]);
|
||||
window.removeEventListener('unhandledrejection', unhandledRejection);
|
||||
window.onerror = oriWindowOnError;
|
||||
done();
|
||||
});
|
||||
} catch (e: any) {
|
||||
window.onerror = oriWindowOnError;
|
||||
}
|
||||
});
|
||||
button.addEventListener('click', listener1);
|
||||
zone1.run(() => {
|
||||
button.addEventListener('click', listener2);
|
||||
});
|
||||
button.addEventListener('click', listener3);
|
||||
button.addEventListener('click', listener4);
|
||||
|
||||
it('should be able to continue to invoke remaining listeners even some listener throw error in the different zones',
|
||||
function(done: DoneFn) {
|
||||
// override global.onerror to prevent jasmine report error
|
||||
let oriWindowOnError = window.onerror;
|
||||
let logs: string[] = [];
|
||||
window.onerror = function(err: any) {
|
||||
logs.push(err);
|
||||
};
|
||||
try {
|
||||
const zone1 = Zone.current.fork({
|
||||
name: 'zone1',
|
||||
onHandleError: (delegate, curr, target, error) => {
|
||||
logs.push(error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
const listener1 = function() {
|
||||
logs.push('listener1');
|
||||
};
|
||||
const listener2 = function() {
|
||||
throw new Error('test1');
|
||||
};
|
||||
const listener3 = function() {
|
||||
throw new Error('test2');
|
||||
};
|
||||
const listener4 = {
|
||||
handleEvent: function() {
|
||||
logs.push('listener2');
|
||||
}
|
||||
};
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
|
||||
button.addEventListener('click', listener1);
|
||||
zone1.run(() => {
|
||||
button.addEventListener('click', listener2);
|
||||
});
|
||||
button.addEventListener('click', listener3);
|
||||
button.addEventListener('click', listener4);
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
fail('should not be here');
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
|
||||
const mouseEvent = document.createEvent('MouseEvent');
|
||||
mouseEvent.initEvent('click', true, true);
|
||||
|
||||
const unhandledRejection = (e: PromiseRejectionEvent) => {
|
||||
fail('should not be here');
|
||||
};
|
||||
window.addEventListener('unhandledrejection', unhandledRejection);
|
||||
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual(['listener1', 'test1', 'listener2', 'Uncaught Error: test2']);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(logs).toEqual(['listener1', 'test1', 'listener2', 'Uncaught Error: test2']);
|
||||
window.removeEventListener('unhandledrejection', unhandledRejection);
|
||||
window.onerror = oriWindowOnError;
|
||||
done();
|
||||
});
|
||||
} catch (e: any) {
|
||||
window.onerror = oriWindowOnError;
|
||||
}
|
||||
});
|
||||
button.dispatchEvent(mouseEvent);
|
||||
expect(logs).toEqual(['listener1', 'listener2']);
|
||||
} catch (e: any) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Re-enable via https://github.com/angular/angular/pull/41526
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue