diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts index fc9cd990f9..32f7deda38 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/HubConnection.spec.ts @@ -390,6 +390,32 @@ describe("HubConnection", () => { connection.receive({ type: 3, invocationId: connection.lastInvocationId }); expect(await observer.completed).toEqual([1, 2, 3]); }); + + it("does not require error function registered", async () => { + let connection = new TestConnection(); + + let hubConnection = new HubConnection(connection); + let observer = hubConnection.stream("testMethod").subscribe({ + next: val => { } + }); + + // Typically this would be called by the transport + // triggers observer.error() + connection.onclose(new Error("Connection lost")); + }); + + it("does not require complete function registered", async () => { + let connection = new TestConnection(); + + let hubConnection = new HubConnection(connection); + let observer = hubConnection.stream("testMethod").subscribe({ + next: val => { } + }); + + // Send completion to trigger observer.complete() + // Expectation is connection.receive will not to throw + connection.receive({ type: 3, invocationId: connection.lastInvocationId }); + }); }); describe("onClose", () => { diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/JasmineUtils.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/JasmineUtils.ts index be452ac96f..c2d3368556 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/JasmineUtils.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/JasmineUtils.ts @@ -7,7 +7,10 @@ export function asyncit(expectation: string, assertion?: () => Promise, tim testFunction = done => { assertion() .then(() => done()) - .catch(() => fail()); + .catch((err) => { + fail(err); + done(); + }); }; } diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Observable.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Observable.ts index 105b01b8d4..e2ea7cb11e 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Observable.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Observable.ts @@ -6,8 +6,8 @@ export interface Observer { closed?: boolean; next: (value: T) => void; - error: (err: any) => void; - complete: () => void; + error?: (err: any) => void; + complete?: () => void; } export interface Observable { @@ -30,13 +30,17 @@ export class Subject implements Observable { public error(err: any): void { for (let observer of this.observers) { - observer.error(err); + if (observer.error) { + observer.error(err); + } } } public complete(): void { for (let observer of this.observers) { - observer.complete(); + if (observer.complete) { + observer.complete(); + } } }