Skip to content

Commit f9565e4

Browse files
committed
fix: show progress for empty files
1 parent 195ce4b commit f9565e4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/resumable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@
760760
if (this.error) {
761761
return 1;
762762
}
763+
if (this.chunks.length === 1) {
764+
this._prevProgress = Math.max(this._prevProgress, this.chunks[0].progress());
765+
return this._prevProgress;
766+
}
763767
// Sum up progress across everything
764768
var bytesLoaded = 0;
765769
each(this.chunks, function (c) {

test/uploadSpec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,24 @@ describe('upload file', function() {
289289
expect(success).toHaveBeenCalled();
290290
expect(retry).toHaveBeenCalled();
291291
});
292+
293+
it('should upload empty file', function () {
294+
var error = jasmine.createSpy('error');
295+
var success = jasmine.createSpy('success');
296+
resumable.on('fileError', error);
297+
resumable.on('fileSuccess', success);
298+
299+
resumable.addFile(new Blob([]));
300+
var file = resumable.files[0];
301+
resumable.upload();
302+
expect(requests.length).toBe(1);
303+
expect(file.progress()).toBe(0);
304+
requests[0].respond(200);
305+
expect(requests.length).toBe(1);
306+
expect(error).not.toHaveBeenCalled();
307+
expect(success).toHaveBeenCalled();
308+
expect(file.progress()).toBe(1);
309+
expect(file.isUploading()).toBe(false);
310+
expect(file.isComplete()).toBe(true);
311+
});
292312
});

0 commit comments

Comments
 (0)