Checking if window.document defined before trying to resolve url

This commit is contained in:
Pawel Kadluczka 2017-09-28 14:28:57 -07:00
parent 4f4fb174ea
commit 602ca479b8
3 changed files with 30 additions and 1 deletions

22
.vscode/launch.json vendored Normal file
View File

@ -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": []
}
]
}

View File

@ -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", () => {
(<any>global).window = {};
expect(() => new HttpConnection("/test"))
.toThrow(new Error("Cannot resolve '/test'."));
delete (<any>global).window;
});
it("starting connection fails if getting id fails", async (done) => {
let options: IHttpConnectionOptions = {
httpClient: <IHttpClient>{

View File

@ -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}'.`);
}