@@ -13,9 +13,8 @@ import {
13
13
DoneHandler ,
14
14
download ,
15
15
DownloadTask ,
16
- DownloadTaskState ,
17
16
ErrorHandler ,
18
- ProgressHandler
17
+ ProgressHandler ,
19
18
} from "react-native-background-downloader" ;
20
19
import RNFS , { exists , readdir , stat , unlink } from "react-native-fs" ;
21
20
import DownloadQueue , { DownloadQueueHandlers } from "../src" ;
@@ -270,7 +269,7 @@ describe("DownloadQueue", () => {
270
269
onBegin : jest . fn ( ) ,
271
270
} ;
272
271
273
- task . state = "DOWNLOADING" as DownloadTaskState . DOWNLOADING ;
272
+ task . state = "DOWNLOADING" ;
274
273
task . totalBytes = 8675309 ;
275
274
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
276
275
@@ -297,7 +296,7 @@ describe("DownloadQueue", () => {
297
296
onBegin : jest . fn ( ) ,
298
297
} ;
299
298
300
- task . state = "PAUSED" as DownloadTaskState . PAUSED ;
299
+ task . state = "PAUSED" ;
301
300
task . totalBytes = 8675309 ;
302
301
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
303
302
@@ -325,7 +324,7 @@ describe("DownloadQueue", () => {
325
324
onDone : jest . fn ( ) ,
326
325
} ;
327
326
328
- task . state = "DONE" as DownloadTaskState . DONE ;
327
+ task . state = "DONE" ;
329
328
task . totalBytes = 8675309 ;
330
329
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
331
330
@@ -343,7 +342,10 @@ describe("DownloadQueue", () => {
343
342
"http://foo.com" ,
344
343
task . totalBytes
345
344
) ;
346
- expect ( handlers . onDone ) . toHaveBeenCalledWith ( "http://foo.com" , `${ RNFS . DocumentDirectoryPath } /DownloadQueue/mydomain/foo` ) ;
345
+ expect ( handlers . onDone ) . toHaveBeenCalledWith (
346
+ "http://foo.com" ,
347
+ `${ RNFS . DocumentDirectoryPath } /DownloadQueue/mydomain/foo`
348
+ ) ;
347
349
expect ( download ) . not . toHaveBeenCalled ( ) ;
348
350
} ) ;
349
351
@@ -354,7 +356,7 @@ describe("DownloadQueue", () => {
354
356
onDone : jest . fn ( ) ,
355
357
} ;
356
358
357
- task . state = "STOPPED" as DownloadTaskState . STOPPED ;
359
+ task . state = "STOPPED" ;
358
360
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
359
361
360
362
await kvfs . write ( "/mydomain/foo" , {
@@ -377,7 +379,7 @@ describe("DownloadQueue", () => {
377
379
onError : jest . fn ( ) ,
378
380
} ;
379
381
380
- task . state = "FAILED" as DownloadTaskState . FAILED ;
382
+ task . state = "FAILED" ;
381
383
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
382
384
383
385
await kvfs . write ( "/mydomain/foo" , {
@@ -389,7 +391,7 @@ describe("DownloadQueue", () => {
389
391
390
392
expect ( jest . getTimerCount ( ) ) . toEqual ( 0 ) ;
391
393
await queue . init ( { domain : "mydomain" , handlers } ) ;
392
- expect ( jest . getTimerCount ( ) ) . toEqual ( 1 ) ; // error retry timer
394
+ expect ( jest . getTimerCount ( ) ) . toEqual ( 1 ) ; // error retry timer
393
395
394
396
await advanceThroughNextTimersAndPromises ( ) ;
395
397
expect ( download ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -407,15 +409,14 @@ describe("DownloadQueue", () => {
407
409
expect ( task . stop ) . not . toHaveBeenCalled ( ) ;
408
410
409
411
queue . terminate ( ) ;
410
- task . state = "PAUSED" as DownloadTaskState . PAUSED ;
412
+ task . state = "PAUSED" ;
411
413
await queue . init ( { domain : "mydomain" } ) ;
412
414
expect ( task . stop ) . toHaveBeenCalledTimes ( 1 ) ;
413
415
414
416
queue . terminate ( ) ;
415
- task . state = "DOWNLOADING" as DownloadTaskState . DOWNLOADING ;
417
+ task . state = "DOWNLOADING" ;
416
418
await queue . init ( { domain : "mydomain" } ) ;
417
419
expect ( task . stop ) . toHaveBeenCalledTimes ( 2 ) ;
418
-
419
420
} ) ;
420
421
421
422
it ( "starts downloads for specs without tasks or files" , async ( ) => {
@@ -442,7 +443,7 @@ describe("DownloadQueue", () => {
442
443
it ( "should stop all active tasks" , async ( ) => {
443
444
const queue = new DownloadQueue ( ) ;
444
445
445
- task . state = "DOWNLOADING" as DownloadTaskState . DOWNLOADING ;
446
+ task . state = "DOWNLOADING" ;
446
447
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
447
448
448
449
await kvfs . write ( "/mydomain/foo" , {
@@ -467,7 +468,7 @@ describe("DownloadQueue", () => {
467
468
onBegin : jest . fn ( ) ,
468
469
} ;
469
470
470
- task . state = "DOWNLOADING" as DownloadTaskState . DOWNLOADING ;
471
+ task . state = "DOWNLOADING" ;
471
472
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
472
473
473
474
await kvfs . write ( "/mydomain/foo" , {
@@ -540,10 +541,10 @@ describe("DownloadQueue", () => {
540
541
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [
541
542
Object . assign ( task , {
542
543
id : assignedId ,
543
- } )
544
+ } ) ,
544
545
] ) ;
545
546
546
- task . state = "PAUSED" as DownloadTaskState . PAUSED ;
547
+ task . state = "PAUSED" ;
547
548
548
549
// Pretend app got launched again by using another queue
549
550
const relaunchQueue = new DownloadQueue ( ) ;
@@ -1050,7 +1051,7 @@ describe("DownloadQueue", () => {
1050
1051
await queue . addUrl ( "http://foo.com" ) ;
1051
1052
1052
1053
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1053
- task . _begin ! ( { expectedBytes : 42 , headers : { } } ) ;
1054
+ task . _begin ! ( { expectedBytes : 42 , headers : { } } ) ;
1054
1055
expect ( handlers . onBegin ) . toHaveBeenCalledTimes ( 1 ) ;
1055
1056
1056
1057
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -1071,7 +1072,7 @@ describe("DownloadQueue", () => {
1071
1072
it ( "should start paused if requested on background downloading task" , async ( ) => {
1072
1073
const queue = new DownloadQueue ( ) ;
1073
1074
1074
- task . state = "DOWNLOADING" as DownloadTaskState . DOWNLOADING ;
1075
+ task . state = "DOWNLOADING" ;
1075
1076
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
1076
1077
1077
1078
await kvfs . write ( "/mydomain/foo" , {
@@ -1094,7 +1095,7 @@ describe("DownloadQueue", () => {
1094
1095
it ( "should start paused if requested on paused background task" , async ( ) => {
1095
1096
const queue = new DownloadQueue ( ) ;
1096
1097
1097
- task . state = "PAUSED" as DownloadTaskState . PAUSED ;
1098
+ task . state = "PAUSED" ;
1098
1099
( checkForExistingDownloads as jest . Mock ) . mockReturnValue ( [ task ] ) ;
1099
1100
1100
1101
await kvfs . write ( "/mydomain/foo" , {
0 commit comments