@@ -40,7 +40,7 @@ describe("httpHandler", () => {
40
40
[ "bizz" , "bazz" ]
41
41
] )
42
42
} ,
43
- body : "FOO" //should be a ReadableStream in real life.
43
+ blob : jest . fn ( ) . mockResolvedValue ( new Blob ( [ "FOO" ] ) ) ,
44
44
} ;
45
45
const mockFetch = jest . fn ( ) . mockResolvedValue ( mockResponse ) ;
46
46
@@ -50,7 +50,8 @@ describe("httpHandler", () => {
50
50
let response = await fetchHttpHandler . handle ( { } as any , { } ) ;
51
51
52
52
expect ( mockFetch . mock . calls . length ) . toBe ( 1 ) ;
53
- expect ( response . response . body ) . toBe ( "FOO" ) ;
53
+ console . log ( response . response . body , typeof response . response . body ) ;
54
+ expect ( await blobToText ( response . response . body ) ) . toBe ( "FOO" ) ;
54
55
} ) ;
55
56
56
57
it ( "properly constructs url" , async ( ) => {
@@ -61,7 +62,7 @@ describe("httpHandler", () => {
61
62
[ "bizz" , "bazz" ]
62
63
] )
63
64
} ,
64
- body : ""
65
+ blob : jest . fn ( ) . mockResolvedValue ( new Blob ( ) ) ,
65
66
} ;
66
67
const mockFetch = jest . fn ( ) . mockResolvedValue ( mockResponse ) ;
67
68
@@ -92,8 +93,7 @@ describe("httpHandler", () => {
92
93
[ "bizz" , "bazz" ]
93
94
] )
94
95
} ,
95
- blob : jest . fn ( ) . mockResolvedValue ( "" ) ,
96
- body : "test"
96
+ blob : jest . fn ( ) . mockResolvedValue ( new Blob ( ) ) ,
97
97
} ;
98
98
const mockFetch = jest . fn ( ) . mockResolvedValue ( mockResponse ) ;
99
99
@@ -119,8 +119,7 @@ describe("httpHandler", () => {
119
119
[ "bizz" , "bazz" ]
120
120
] )
121
121
} ,
122
- blob : jest . fn ( ) . mockResolvedValue ( "" ) ,
123
- body : "test"
122
+ blob : jest . fn ( ) . mockResolvedValue ( new Blob ( ) ) ,
124
123
} ;
125
124
const mockFetch = jest . fn ( ) . mockResolvedValue ( mockResponse ) ;
126
125
( global as any ) . fetch = mockFetch ;
@@ -145,8 +144,7 @@ describe("httpHandler", () => {
145
144
[ "bizz" , "bazz" ]
146
145
] )
147
146
} ,
148
- blob : jest . fn ( ) . mockResolvedValue ( "" ) ,
149
- body : "test"
147
+ blob : jest . fn ( ) . mockResolvedValue ( new Blob ( ) ) ,
150
148
} ;
151
149
const mockFetch = jest . fn ( ) . mockResolvedValue ( mockResponse ) ;
152
150
( global as any ) . fetch = mockFetch ;
@@ -207,4 +205,20 @@ describe("httpHandler", () => {
207
205
expect ( httpHandler . destroy ( ) ) . toBeUndefined ( ) ;
208
206
} ) ;
209
207
} ) ;
208
+
209
+ // The Blob implementation does not implement Blob.text, so we deal with it here.
210
+ async function blobToText ( blob : Blob ) : Promise < string > {
211
+ const reader = new FileReader ( ) ;
212
+
213
+ return new Promise ( ( resolve ) => {
214
+ // This fires after the blob has been read/loaded.
215
+ reader . addEventListener ( 'loadend' , ( e ) => {
216
+ const text = e . target ! . result as string ;
217
+ resolve ( text ) ;
218
+ } ) ;
219
+
220
+ // Start reading the blob as text.
221
+ reader . readAsText ( blob ) ;
222
+ } ) ;
223
+ }
210
224
} ) ;
0 commit comments