Skip to content

Commit ec19fc5

Browse files
jsayolsphippen
authored andcommitted
fix(storage): allow missing some methods in UploadTask observer (#41)
1 parent 2801c34 commit ec19fc5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/storage/implementation/observer.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ export class Observer<T> {
4646
this.error = opt_error || null;
4747
this.complete = opt_complete || null;
4848
} else {
49-
const observer = nextOrObserver as {[name: string]: null};
50-
this.next = observer['next'] as (NextFn<T> | null);
51-
this.error = observer['error'] as (ErrorFn | null);
52-
this.complete = observer['complete'] as (CompleteFn | null);
49+
const observer = nextOrObserver as {
50+
next?: NextFn<T> | null;
51+
error?: ErrorFn | null;
52+
complete?: CompleteFn | null;
53+
};
54+
this.next = observer.next || null;
55+
this.error = observer.error || null;
56+
this.complete = observer.complete || null;
5357
}
5458
}
5559
}

tests/storage/browser/task_test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ describe("Firebase Storage > Upload Task", () => {
231231
});
232232
});
233233
});
234+
it("Works properly with an observer missing the 'next' method", () => {
235+
const authWrapper = authWrapperWithHandler(fakeServerHandler());
236+
const task = new UploadTask(
237+
{} as Reference, authWrapper, testLocation, mappings, smallBlob);
238+
return fbsPromise.make<void>((resolve, reject) => {
239+
task.on(
240+
TaskEvent.STATE_CHANGED, {
241+
error: err => { assert.fail('Unexpected upload failure'); },
242+
complete: () => { resolve(null); }
243+
});
244+
});
245+
});
234246

235247
function runNormalUploadTest(blob: FbsBlob): Promise<void> {
236248
const authWrapper = authWrapperWithHandler(fakeServerHandler());

0 commit comments

Comments
 (0)