1
- import * as sinon from 'sinon' ;
2
1
import { expect } from 'chai' ;
2
+ import * as sinon from 'sinon' ;
3
3
import { ExceptionsZone } from '../../../errors/exceptions-zone' ;
4
- import { UNHANDLED_RUNTIME_EXCEPTION } from '../../../errors/messages' ;
5
4
6
5
describe ( 'ExceptionsZone' , ( ) => {
6
+ const rethrow = err => {
7
+ throw err ;
8
+ } ;
9
+
7
10
describe ( 'run' , ( ) => {
8
11
let callback : sinon . SinonSpy ;
9
12
beforeEach ( ( ) => {
10
13
callback = sinon . spy ( ) ;
11
14
} ) ;
12
15
it ( 'should call callback' , ( ) => {
13
- ExceptionsZone . run ( callback as any ) ;
16
+ ExceptionsZone . run ( callback as any , rethrow ) ;
14
17
expect ( callback . called ) . to . be . true ;
15
18
} ) ;
16
19
describe ( 'when callback throws exception' , ( ) => {
17
20
const exceptionHandler = {
18
21
handle : ( ) => { } ,
19
22
} ;
20
23
let handleSpy : sinon . SinonSpy ;
21
- beforeEach ( ( ) => {
24
+ before ( ( ) => {
22
25
( ExceptionsZone as any ) . exceptionHandler = exceptionHandler ;
23
26
handleSpy = sinon . spy ( exceptionHandler , 'handle' ) ;
24
27
} ) ;
25
- it ( 'should call "handle" method of exceptionHandler and throws UNHANDLED_RUNTIME_EXCEPTION ' , ( ) => {
28
+ it ( 'should call "handle" method of exceptionHandler and rethrows ' , ( ) => {
26
29
const throwsCallback = ( ) => {
27
- throw 3 ;
30
+ throw new Error ( '' ) ;
28
31
} ;
29
- expect ( ( ) => ExceptionsZone . run ( throwsCallback ) ) . to . throws (
30
- UNHANDLED_RUNTIME_EXCEPTION ,
31
- ) ;
32
+ expect ( ( ) => ExceptionsZone . run ( throwsCallback , rethrow ) ) . to . throws ( ) ;
32
33
expect ( handleSpy . called ) . to . be . true ;
33
34
} ) ;
34
35
} ) ;
@@ -39,24 +40,24 @@ describe('ExceptionsZone', () => {
39
40
callback = sinon . spy ( ) ;
40
41
} ) ;
41
42
it ( 'should call callback' , async ( ) => {
42
- await ExceptionsZone . asyncRun ( callback as any ) ;
43
+ await ExceptionsZone . asyncRun ( callback as any , rethrow ) ;
43
44
expect ( callback . called ) . to . be . true ;
44
45
} ) ;
45
46
describe ( 'when callback throws exception' , ( ) => {
46
47
const exceptionHandler = {
47
48
handle : ( ) => { } ,
48
49
} ;
49
50
let handleSpy : sinon . SinonSpy ;
50
- beforeEach ( ( ) => {
51
+ before ( ( ) => {
51
52
( ExceptionsZone as any ) . exceptionHandler = exceptionHandler ;
52
53
handleSpy = sinon . spy ( exceptionHandler , 'handle' ) ;
53
54
} ) ;
54
- it ( 'should call "handle" method of exceptionHandler and throws UNHANDLED_RUNTIME_EXCEPTION ' , async ( ) => {
55
+ it ( 'should call "handle" method of exceptionHandler and rethrows error ' , async ( ) => {
55
56
const throwsCallback = ( ) => {
56
- throw 3 ;
57
+ throw new Error ( '' ) ;
57
58
} ;
58
- expect ( ExceptionsZone . asyncRun ( throwsCallback ) ) . to . eventually . be
59
- . rejected ;
59
+ expect ( ExceptionsZone . asyncRun ( throwsCallback , rethrow ) ) . to . eventually
60
+ . be . rejected ;
60
61
} ) ;
61
62
} ) ;
62
63
} ) ;
0 commit comments