diff --git a/src/services/fileService.ts b/src/services/fileService.ts index 303301c..cb99b2b 100644 --- a/src/services/fileService.ts +++ b/src/services/fileService.ts @@ -10,7 +10,9 @@ const create = (bytes: Uint8Array[], type: string, name: string): File|Blob => { try { return new File(bytes, name, {type}); } catch (error) { - return new Blob(bytes, {type}); + const blob = new Blob(bytes, {type}); + blob.name = name; + return blob; } }; diff --git a/src/types/Blob.d.ts b/src/types/Blob.d.ts new file mode 100644 index 0000000..b60c760 --- /dev/null +++ b/src/types/Blob.d.ts @@ -0,0 +1,3 @@ +interface Blob { + name: string +} diff --git a/tests/services/fileService.test.ts b/tests/services/fileService.test.ts index d1e5153..f8399d9 100644 --- a/tests/services/fileService.test.ts +++ b/tests/services/fileService.test.ts @@ -74,11 +74,15 @@ describe('fileService', (): void => { actualFile = fileService.create([bytes], type, name); }); - it('should create a blob with size', (): void => { + it('should create a file with name', (): void => { + expect(actualFile.name).toBe(name); + }); + + it('should create a file with size', (): void => { expect(actualFile.size).toBe(bytes.toString().length); }); - it('should create a blob with type', (): void => { + it('should create a file with type', (): void => { expect(actualFile.type).toBe(type); }); }); @@ -96,6 +100,10 @@ describe('fileService', (): void => { actualBlob = fileService.create([bytes], type, name); }); + it('should create a blob with name', (): void => { + expect(actualBlob.name).toBe(name); + }); + it('should create a blob with size', (): void => { expect(actualBlob.size).toBe(bytes.toString().length); });