From 602ca479b8372e7672b4fd2afefccd62488ef6a3 Mon Sep 17 00:00:00 2001 From: Pawel Kadluczka Date: Thu, 28 Sep 2017 14:28:57 -0700 Subject: [PATCH] Checking if window.document defined before trying to resolve url --- .vscode/launch.json | 22 +++++++++++++++++++ .../Connection.spec.ts | 7 ++++++ .../HttpConnection.ts | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..313c0a9d9e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceRoot}/client-ts/node_modules/jasmine/bin/jasmine.js", + "args": ["JASMINE_CONFIG_PATH=${workspaceRoot}/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/jasmine.json"], + "cwd": "${workspaceRoot}/client-ts", + "outFiles": [] + }, + { + "type": "node", + "request": "attach", + "name": "Attach to Port", + "address": "localhost", + "port": 5858, + "outFiles": [] + } + ] +} \ No newline at end of file diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts index bfa3c9f9f4..335dc9ffc1 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts @@ -14,6 +14,13 @@ describe("Connection", () => { .toThrow(new Error("Cannot resolve '/test'.")); }); + it("cannot be created with relative url if window object is not present", () => { + (global).window = {}; + expect(() => new HttpConnection("/test")) + .toThrow(new Error("Cannot resolve '/test'.")); + delete (global).window; + }); + it("starting connection fails if getting id fails", async (done) => { let options: IHttpConnectionOptions = { httpClient: { diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts index 733454c6e8..585815aba3 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/HttpConnection.ts @@ -162,7 +162,7 @@ export class HttpConnection implements IConnection { return url; } - if (typeof window === 'undefined') { + if (typeof window === 'undefined' || !window || !window.document) { throw new Error(`Cannot resolve '${url}'.`); }