11import * as sinon from 'sinon' ;
22import { expect } from 'chai' ;
3- import { ExceptionsZone } from '../exceptions-zone' ;
4- import { UNHANDLED_RUNTIME_EXCEPTION } from '../messages' ;
3+ import { ExceptionsZone } from '../../../errors/ exceptions-zone' ;
4+ import { UNHANDLED_RUNTIME_EXCEPTION } from '../../../errors/ messages' ;
55
66describe ( 'ExceptionsZone' , ( ) => {
77 describe ( 'run' , ( ) => {
@@ -31,4 +31,30 @@ describe('ExceptionsZone', () => {
3131 } ) ;
3232 } ) ;
3333 } ) ;
34+ describe ( 'asyncRun' , ( ) => {
35+ let callback : sinon . SinonSpy ;
36+ beforeEach ( ( ) => {
37+ callback = sinon . spy ( ) ;
38+ } ) ;
39+ it ( 'should call callback' , async ( ) => {
40+ await ExceptionsZone . asyncRun ( callback as any ) ;
41+ expect ( callback . called ) . to . be . true ;
42+ } ) ;
43+ describe ( 'when callback throws exception' , ( ) => {
44+ const exceptionHandler = {
45+ handle : ( ) => { } ,
46+ } ;
47+ let handleSpy : sinon . SinonSpy ;
48+ beforeEach ( ( ) => {
49+ ( ExceptionsZone as any ) . exceptionHandler = exceptionHandler ;
50+ handleSpy = sinon . spy ( exceptionHandler , 'handle' ) ;
51+ } ) ;
52+ it ( 'should call "handle" method of exceptionHandler and throws UNHANDLED_RUNTIME_EXCEPTION' , async ( ) => {
53+ const throwsCallback = ( ) => {
54+ throw 3 ;
55+ } ;
56+ expect ( ExceptionsZone . asyncRun ( throwsCallback ) ) . to . eventually . be . rejected ;
57+ } ) ;
58+ } ) ;
59+ } ) ;
3460} ) ;
0 commit comments