fix export initDownloader & tests

This commit is contained in:
Kesha Antonov
2023-07-17 14:13:22 +03:00
parent 1c22e0602e
commit e4a7730c81
3 changed files with 14 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import RNBackgroundDownloader, { initDownloader } from '../index' import RNBackgroundDownloader from '../index'
import DownloadTask from '../lib/downloadTask' import DownloadTask from '../lib/downloadTask'
import { NativeModules, NativeEventEmitter } from 'react-native' import { NativeModules, NativeEventEmitter } from 'react-native'
@@ -130,12 +130,18 @@ test('stop', () => {
}) })
test('initDownloader', () => { test('initDownloader', () => {
return RNBackgroundDownloader.initDownloader() jest.mock('react-native/Libraries/Utilities/Platform', () => {
.then(res => { const Platform = jest.requireActual(
'react-native/Libraries/Utilities/Platform'
)
Platform.OS = 'android'
return Platform
})
const res = RNBackgroundDownloader.initDownloader()
expect(RNBackgroundDownloaderNative.initDownloader).toHaveBeenCalled() expect(RNBackgroundDownloaderNative.initDownloader).toHaveBeenCalled()
expect(res).toBe(undefined) expect(res).toBe(undefined)
}) })
})
test('checkForExistingDownloads', () => { test('checkForExistingDownloads', () => {
return RNBackgroundDownloader.checkForExistingDownloads() return RNBackgroundDownloader.checkForExistingDownloads()

2
index.d.ts vendored
View File

@@ -79,7 +79,7 @@ export type EnsureDownloadsAreRunning = () => Promise<void>;
export interface InitDownloaderOptions { export interface InitDownloaderOptions {
type?: 'parallel' | 'sequential' | null; type?: 'parallel' | 'sequential' | null;
} }
export type InitDownloader = (options: InitDownloaderOptions) => Promise<void>; export type InitDownloader = (options: InitDownloaderOptions) => undefined;
export interface DownloadOption { export interface DownloadOption {
id: string; id: string;

View File

@@ -134,6 +134,7 @@ export const Priority = {
} }
export default { export default {
initDownloader,
download, download,
checkForExistingDownloads, checkForExistingDownloads,
ensureDownloadsAreRunning, ensureDownloadsAreRunning,