some chages

This commit is contained in:
Elad Gil
2018-07-03 10:45:23 +03:00
parent 7d79cb095e
commit d283d485f4
3 changed files with 15 additions and 17 deletions
+5 -5
View File
@@ -41,7 +41,7 @@ test('begin event', () => {
});
NativeEventEmitter.listeners.downloadBegin({
id: 'testBegin',
expctedBytes: 9001
expectedBytes: 9001
});
});
});
@@ -159,17 +159,17 @@ test('wrong handler type', () => {
expect(() => {
dt.begin('not function');
}).toThrow('handler must be a function');
}).toThrow();
expect(() => {
dt.progress(7);
}).toThrow('handler must be a function');
}).toThrow();
expect(() => {
dt.done({iamnota: 'function'});
}).toThrow('handler must be a function');
}).toThrow();
expect(() => {
dt.error('not function');
}).toThrow('handler must be a function');
}).toThrow();
});
+1
View File
@@ -53,6 +53,7 @@ export function checkForExistingDownloads() {
if (taskInfo.bytesWritten === taskInfo.totalBytes) {
task.state = 'DONE';
} else {
// IOS completed the download but it was not done.
return null;
}
}
+9 -12
View File
@@ -1,6 +1,11 @@
import { NativeModules } from 'react-native';
const { RNBackgroundDownload } = NativeModules;
function validateHandler(handler) {
if (!(typeof handler === 'function')) {
throw new TypeError(`[RNBackgroundDownload] expected argument to be a function, got: ${typeof handler}`);
}
}
export default class DownloadTask {
state = 'PENDING'
percent = 0
@@ -19,33 +24,25 @@ export default class DownloadTask {
}
begin(handler) {
if (!(typeof handler === 'function')) {
throw new TypeError('handler must be a function');
}
validateHandler(handler);
this._beginHandler = handler;
return this;
}
progress(handler) {
if (!(typeof handler === 'function')) {
throw new TypeError('handler must be a function');
}
validateHandler(handler);
this._progressHandler = handler;
return this;
}
done(handler) {
if (!(typeof handler === 'function')) {
throw new TypeError('handler must be a function');
}
validateHandler(handler);
this._doneHandler = handler;
return this;
}
error(handler) {
if (!(typeof handler === 'function')) {
throw new TypeError('handler must be a function');
}
validateHandler(handler);
this._errorHandler = handler;
return this;
}