@@ -22,7 +22,7 @@ describe('process related test', () => {
2222 } ) ;
2323 } ) ;
2424 } ) ;
25- it ( 'process.nextTick should be excuted before macroTask and promise' , ( done ) => {
25+ it ( 'process.nextTick should be executed before macroTask and promise' , ( done ) => {
2626 zoneA . run ( function ( ) {
2727 setTimeout ( ( ) => {
2828 result . push ( 'timeout' ) ;
@@ -64,13 +64,16 @@ describe('process related test', () => {
6464 done ( ) ;
6565 } ) ;
6666 } ) ;
67- it ( 'should support window.addEventListener(unhandledrejection)' , function ( done ) {
67+
68+ it ( 'should support process.on(unhandledRejection)' , function ( done ) {
6869 const hookSpy = jasmine . createSpy ( 'hook' ) ;
6970 Zone [ zoneSymbol ( 'ignoreConsoleErrorUncaughtError' ) ] = true ;
7071 Zone . current . fork ( { name : 'promise' } ) . run ( function ( ) {
71- process . on ( 'unhandledRejection' , function ( reason , promise ) {
72+ const listener = function ( reason , promise ) {
7273 hookSpy ( promise , reason . message ) ;
73- } ) ;
74+ process . removeListener ( 'unhandledRejection' , listener ) ;
75+ } ;
76+ process . on ( 'unhandledRejection' , listener ) ;
7477 const p = new Promise ( ( resolve , reject ) => {
7578 throw new Error ( 'promise error' ) ;
7679 } ) ;
@@ -82,13 +85,15 @@ describe('process related test', () => {
8285 } ) ;
8386 } ) ;
8487
85- it ( 'should support window.addEventListener (rejectionHandled)' , function ( done ) {
88+ it ( 'should support process.on (rejectionHandled)' , function ( done ) {
8689 Zone [ zoneSymbol ( 'ignoreConsoleErrorUncaughtError' ) ] = true ;
8790 Zone . current . fork ( { name : 'promise' } ) . run ( function ( ) {
88- process . on ( 'rejectionHandled' , function ( promise ) {
91+ const listener = function ( promise ) {
8992 expect ( promise ) . toEqual ( p ) ;
93+ process . removeListener ( 'rejectionHandled' , listener ) ;
9094 done ( ) ;
91- } ) ;
95+ } ;
96+ process . on ( 'rejectionHandled' , listener ) ;
9297 const p = new Promise ( ( resolve , reject ) => {
9398 throw new Error ( 'promise error' ) ;
9499 } ) ;
@@ -98,4 +103,30 @@ describe('process related test', () => {
98103 } , 10 ) ;
99104 } ) ;
100105 } ) ;
106+
107+ it ( 'should support multiple process.on(unhandledRejection)' , function ( done ) {
108+ const hookSpy = jasmine . createSpy ( 'hook' ) ;
109+ Zone [ zoneSymbol ( 'ignoreConsoleErrorUncaughtError' ) ] = true ;
110+ Zone . current . fork ( { name : 'promise' } ) . run ( function ( ) {
111+ const listener1 = function ( reason , promise ) {
112+ hookSpy ( promise , reason . message ) ;
113+ process . removeListener ( 'unhandledRejection' , listener1 ) ;
114+ } ;
115+ const listener2 = function ( reason , promise ) {
116+ hookSpy ( promise , reason . message ) ;
117+ process . removeListener ( 'unhandledRejection' , listener2 ) ;
118+ } ;
119+ process . on ( 'unhandledRejection' , listener1 ) ;
120+ process . on ( 'unhandledRejection' , listener2 ) ;
121+ const p = new Promise ( ( resolve , reject ) => {
122+ throw new Error ( 'promise error' ) ;
123+ } ) ;
124+
125+ setTimeout ( function ( ) {
126+ expect ( hookSpy . calls . count ( ) ) . toBe ( 2 ) ;
127+ expect ( hookSpy . calls . allArgs ( ) ) . toEqual ( [ [ p , 'promise error' ] , [ p , 'promise error' ] ] ) ;
128+ done ( ) ;
129+ } , 10 ) ;
130+ } ) ;
131+ } ) ;
101132} ) ;
0 commit comments