This repository was archived by the owner on Feb 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +15
-17
lines changed Expand file tree Collapse file tree 3 files changed +15
-17
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ test('begin event', () => {
41
41
} ) ;
42
42
NativeEventEmitter . listeners . downloadBegin ( {
43
43
id : 'testBegin' ,
44
- expctedBytes : 9001
44
+ expectedBytes : 9001
45
45
} ) ;
46
46
} ) ;
47
47
} ) ;
@@ -159,17 +159,17 @@ test('wrong handler type', () => {
159
159
160
160
expect ( ( ) => {
161
161
dt . begin ( 'not function' ) ;
162
- } ) . toThrow ( 'handler must be a function' ) ;
162
+ } ) . toThrow ( ) ;
163
163
164
164
expect ( ( ) => {
165
165
dt . progress ( 7 ) ;
166
- } ) . toThrow ( 'handler must be a function' ) ;
166
+ } ) . toThrow ( ) ;
167
167
168
168
expect ( ( ) => {
169
169
dt . done ( { iamnota : 'function' } ) ;
170
- } ) . toThrow ( 'handler must be a function' ) ;
170
+ } ) . toThrow ( ) ;
171
171
172
172
expect ( ( ) => {
173
173
dt . error ( 'not function' ) ;
174
- } ) . toThrow ( 'handler must be a function' ) ;
174
+ } ) . toThrow ( ) ;
175
175
} ) ;
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ export function checkForExistingDownloads() {
53
53
if ( taskInfo . bytesWritten === taskInfo . totalBytes ) {
54
54
task . state = 'DONE' ;
55
55
} else {
56
+ // IOS completed the download but it was not done.
56
57
return null ;
57
58
}
58
59
}
Original file line number Diff line number Diff line change 1
1
import { NativeModules } from 'react-native' ;
2
2
const { RNBackgroundDownload } = NativeModules ;
3
3
4
+ function validateHandler ( handler ) {
5
+ if ( ! ( typeof handler === 'function' ) ) {
6
+ throw new TypeError ( `[RNBackgroundDownload] expected argument to be a function, got: ${ typeof handler } ` ) ;
7
+ }
8
+ }
4
9
export default class DownloadTask {
5
10
state = 'PENDING'
6
11
percent = 0
@@ -19,33 +24,25 @@ export default class DownloadTask {
19
24
}
20
25
21
26
begin ( handler ) {
22
- if ( ! ( typeof handler === 'function' ) ) {
23
- throw new TypeError ( 'handler must be a function' ) ;
24
- }
27
+ validateHandler ( handler ) ;
25
28
this . _beginHandler = handler ;
26
29
return this ;
27
30
}
28
31
29
32
progress ( handler ) {
30
- if ( ! ( typeof handler === 'function' ) ) {
31
- throw new TypeError ( 'handler must be a function' ) ;
32
- }
33
+ validateHandler ( handler ) ;
33
34
this . _progressHandler = handler ;
34
35
return this ;
35
36
}
36
37
37
38
done ( handler ) {
38
- if ( ! ( typeof handler === 'function' ) ) {
39
- throw new TypeError ( 'handler must be a function' ) ;
40
- }
39
+ validateHandler ( handler ) ;
41
40
this . _doneHandler = handler ;
42
41
return this ;
43
42
}
44
43
45
44
error ( handler ) {
46
- if ( ! ( typeof handler === 'function' ) ) {
47
- throw new TypeError ( 'handler must be a function' ) ;
48
- }
45
+ validateHandler ( handler ) ;
49
46
this . _errorHandler = handler ;
50
47
return this ;
51
48
}
You can’t perform that action at this time.
0 commit comments