diff --git a/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.ts b/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.ts index a3481c7..4f3d4d1 100644 --- a/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.ts +++ b/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.ts @@ -30,6 +30,7 @@ export function getSearchQueryParamsAsObject(str: string): { [key: string]: any; } { const obj: { [key: string]: any } = {}; + if (str.indexOf("?") === -1) return obj; let queryString = str.substring(str.indexOf("?")); queryString = queryString.split("#").shift(); if (!queryString) return obj; diff --git a/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.unit.test.ts b/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.unit.test.ts index f56bf34..c6ceb56 100644 --- a/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.unit.test.ts +++ b/src/helpers/getSearchQueryParamsAsObject/getSearchQueryParamsAsObject.unit.test.ts @@ -1,8 +1,16 @@ import { getSearchQueryParamsAsObject } from "./getSearchQueryParamsAsObject"; import { Actor } from "../../XAPI"; +test("handles url with no query parameters", () => { + return expect( + Object.keys(getSearchQueryParamsAsObject("http://localhost:1234/")).length + ).toEqual(0); +}); + test("handles empty querystring", () => { - return expect(getSearchQueryParamsAsObject("")).toMatchObject({}); + return expect(Object.keys(getSearchQueryParamsAsObject("")).length).toEqual( + 0 + ); }); test("converts querystring into object", () => {