File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import fetchMock from "jest-fetch-mock" ;
3
+ import { RestTemplate } from '../../../src/http/client' ;
4
+
5
+ describe ( "passport control" , ( ) => {
6
+
7
+ let template : RestTemplate ;
8
+
9
+ beforeAll ( ( ) => {
10
+ fetchMock . enableMocks ( ) ;
11
+
12
+ template = new RestTemplate ( ) ;
13
+ } ) ;
14
+
15
+ it ( "should handle error correctly" , async ( ) => {
16
+ // Arrange
17
+ template . errorHandler = {
18
+ hasError : ( ) => true ,
19
+ handleError : ( ) => { throw Error ( '' ) }
20
+ }
21
+ fetchMock . mockIf ( 'https://localhost' , req => {
22
+ return Promise . resolve ( {
23
+ status : 500 ,
24
+ body : JSON . stringify ( { message : 'Error' } ) ,
25
+ headers : {
26
+ 'content-type' : 'application/json'
27
+ }
28
+ } ) ;
29
+ } ) ;
30
+
31
+ // Act
32
+ let result : any = undefined ;
33
+
34
+ try {
35
+ await template . exchange ( 'https://localhost' , 'GET' ) ;
36
+ } catch ( error ) {
37
+ result = 'error'
38
+ }
39
+
40
+ // Assert
41
+ expect ( result ) . toEqual ( 'error' ) ;
42
+ } ) ;
43
+
44
+ } ) ;
You can’t perform that action at this time.
0 commit comments