3
3
import {
4
4
ReadableStream ,
5
5
ReadableStreamDefaultReadResult ,
6
- } from 'web-streams-polyfill/ponyfill ' ;
6
+ } from 'web-streams-polyfill' ;
7
7
import { renderHook , act } from '@testing-library/react-hooks' ;
8
8
import useDownloader , { jsDownload } from '../index' ;
9
9
import { WindowDownloaderEmbedded } from '../types' ;
@@ -21,7 +21,8 @@ const expectedKeys = [
21
21
beforeAll ( ( ) => {
22
22
global . window . fetch = fetch as Extract < WindowOrWorkerGlobalScope , 'fetch' > ;
23
23
global . Response = Response ;
24
- global . ReadableStream = ReadableStream ;
24
+ global . ReadableStream =
25
+ ReadableStream as unknown as typeof global . ReadableStream ;
25
26
} ) ;
26
27
27
28
describe ( 'useDownloader successes' , ( ) => {
@@ -240,10 +241,14 @@ describe('useDownloader failures', () => {
240
241
241
242
describe ( 'Tests without msSaveBlob' , ( ) => {
242
243
beforeAll ( ( ) => {
243
- ( window as unknown as WindowDownloaderEmbedded ) . navigator . msSaveBlob =
244
- undefined ;
245
- window . URL . createObjectURL = ( ) => null ;
246
- window . URL . revokeObjectURL = ( ) => null ;
244
+ const currentWindow = window as unknown as WindowDownloaderEmbedded ;
245
+
246
+ currentWindow . navigator . msSaveBlob = undefined ;
247
+
248
+ if ( currentWindow . URL ) {
249
+ currentWindow . URL . createObjectURL = ( ) => null ;
250
+ currentWindow . URL . revokeObjectURL = ( ) => null ;
251
+ }
247
252
} ) ;
248
253
249
254
it ( 'should test with URL and being revoked' , async ( ) => {
@@ -262,17 +267,22 @@ describe('useDownloader failures', () => {
262
267
} ) ;
263
268
264
269
it ( 'should test with URL via webkitURL' , ( ) => {
265
- window . URL = undefined ;
266
- window . webkitURL . createObjectURL = ( ) => null ;
270
+ const currentWindow = window as unknown as WindowDownloaderEmbedded ;
267
271
268
- const createObjectWebkitURLSpy = jest . spyOn (
269
- window . webkitURL ,
270
- 'createObjectURL'
271
- ) ;
272
+ currentWindow . URL = undefined ;
272
273
273
- jsDownload ( new Blob ( [ 'abcde' ] ) , 'test' ) ;
274
+ if ( currentWindow . webkitURL ) {
275
+ currentWindow . webkitURL . createObjectURL = ( ) => null ;
276
+
277
+ const createObjectWebkitURLSpy = jest . spyOn (
278
+ window . webkitURL ,
279
+ 'createObjectURL'
280
+ ) ;
281
+
282
+ jsDownload ( new Blob ( [ 'abcde' ] ) , 'test' ) ;
274
283
275
- expect ( createObjectWebkitURLSpy ) . toHaveBeenCalled ( ) ;
284
+ expect ( createObjectWebkitURLSpy ) . toHaveBeenCalled ( ) ;
285
+ }
276
286
} ) ;
277
287
} ) ;
278
288
} ) ;
0 commit comments