1import { mockProperty, unmockProperty } from 'jest-expo'; 2 3import ExponentFileSystem from '../ExponentFileSystem'; 4import * as FileSystem from '../FileSystem'; 5 6describe('FileSystem', () => { 7 describe('DownloadResumable', () => { 8 const remoteUri = 'http://techslides.com/demos/sample-videos/small.mp4'; 9 const localUri = FileSystem.documentDirectory + 'small.mp4'; 10 const options = {}; 11 const resumeData = ''; 12 const fakeObject = { 13 url: remoteUri, 14 fileUri: localUri, 15 options, 16 resumeData, 17 }; 18 const callback = jest.fn(); 19 let downloadResumable; 20 beforeEach(() => { 21 downloadResumable = FileSystem.createDownloadResumable( 22 remoteUri, 23 localUri, 24 options, 25 callback, 26 resumeData 27 ); 28 }); 29 30 it(`downloads with the correct props`, async () => { 31 await downloadResumable.downloadAsync(); 32 33 expect(ExponentFileSystem.downloadResumableStartAsync).toHaveBeenCalledWith( 34 remoteUri, 35 localUri, 36 downloadResumable._uuid, 37 options, 38 resumeData 39 ); 40 }); 41 42 it(`pauses correctly`, async () => { 43 mockProperty( 44 ExponentFileSystem, 45 'downloadResumablePauseAsync', 46 jest.fn(async () => fakeObject) 47 ); 48 49 const downloadPauseState = await downloadResumable.pauseAsync(); 50 51 expect(downloadPauseState).toMatchObject(fakeObject); 52 53 expect(ExponentFileSystem.downloadResumablePauseAsync).toHaveBeenCalledWith( 54 downloadResumable._uuid 55 ); 56 57 unmockProperty(ExponentFileSystem, 'downloadResumablePauseAsync'); 58 }); 59 60 it(`pauses with error`, async () => { 61 await expect(downloadResumable.pauseAsync()).rejects.toThrow(); 62 }); 63 64 it(`resumes correctly`, async () => { 65 mockProperty( 66 ExponentFileSystem, 67 'downloadResumableStartAsync', 68 jest.fn(async () => fakeObject) 69 ); 70 71 const downloadPauseState = await downloadResumable.resumeAsync(); 72 73 expect(downloadPauseState).toMatchObject(fakeObject); 74 75 expect(ExponentFileSystem.downloadResumableStartAsync).toHaveBeenCalledWith( 76 remoteUri, 77 localUri, 78 downloadResumable._uuid, 79 options, 80 resumeData 81 ); 82 }); 83 84 it(`has same save state as original input`, async () => { 85 const downloadPauseState = await downloadResumable.savable(); 86 87 expect(downloadPauseState).toMatchObject(fakeObject); 88 }); 89 }); 90}); 91