diff --git a/TestRunner/app/tests/URL.js b/TestRunner/app/tests/URL.js index a121ec31..5ebda35c 100644 --- a/TestRunner/app/tests/URL.js +++ b/TestRunner/app/tests/URL.js @@ -1,31 +1,31 @@ describe("Test URL ", function () { - -it("Test invalid URL parsing", function(){ -var exceptionCaught = false; - try { - const url = new URL(''); + + it("Test invalid URL parsing", function(){ + var exceptionCaught = false; + try { + const url = new URL(''); }catch(e){ - exceptionCaught = true; + exceptionCaught = true; } expect(exceptionCaught).toBe(true); -}); - -it("Test valid URL parsing", function(){ -var exceptionCaught = false; - try { - const url = new URL('https://google.com'); + }); + + it("Test valid URL parsing", function(){ + var exceptionCaught = false; + try { + const url = new URL('https://google.com'); }catch(e){ - exceptionCaught = true; + exceptionCaught = true; } expect(exceptionCaught).toBe(false); -}); - - -it("Test URL fields", function(){ -var exceptionCaught = false; - const url = new URL('https://google.com'); - expect(url.protocol).toBe('https:'); - expect(url.hostname).toBe('google.com'); -}); - + }); + + + it("Test URL fields", function(){ + var exceptionCaught = false; + const url = new URL('https://google.com'); + expect(url.protocol).toBe('https:'); + expect(url.hostname).toBe('google.com'); + }); + }); diff --git a/TestRunner/app/tests/URLSearchParams.js b/TestRunner/app/tests/URLSearchParams.js index 51c0b3e7..6a722585 100644 --- a/TestRunner/app/tests/URLSearchParams.js +++ b/TestRunner/app/tests/URLSearchParams.js @@ -1,56 +1,64 @@ describe("Test URLSearchParams ", function () { - - -it("Test URLSearchParams keys", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -const keys = params.keys(); -expect(keys[0]).toBe("foo"); -expect(keys[1]).toBe("bar"); -}); - -it("Test URLSearchParams values", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -const values = params.values(); -expect(values[0]).toBe("1"); -expect(values[1]).toBe("2"); -}); - - -it("Test URLSearchParams entries", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -const entries = params.entries(); -expect(entries[0][0]).toBe("foo"); -expect(entries[0][1]).toBe("1"); - -expect(entries[1][0]).toBe("bar"); -expect(entries[1][1]).toBe("2"); - -}); - - -it("Test URLSearchParams size", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -expect(params.size).toBe(2); -}); - -it("Test URLSearchParams append", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -params.append("first", "Osei"); -expect(params.get("first")).toBe("Osei"); -}); - - -it("Test URLSearchParams delete", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -params.append("first", "Osei"); -params.delete("first"); -expect(params.get("first")).toBe(undefined); -}); - - -it("Test URLSearchParams has", function(){ -const params = new URLSearchParams("foo=1&bar=2"); -expect(params.has("foo")).toBe(true); -}); - + const fooBar = "foo=1&bar=2"; + it("Test URLSearchParams keys", function(){ + const params = new URLSearchParams(fooBar); + const keys = params.keys(); + expect(keys[0]).toBe("foo"); + expect(keys[1]).toBe("bar"); + }); + + it("Test URLSearchParams values", function(){ + const params = new URLSearchParams(fooBar); + const values = params.values(); + expect(values[0]).toBe("1"); + expect(values[1]).toBe("2"); + }); + + + it("Test URLSearchParams entries", function(){ + const params = new URLSearchParams(fooBar); + const entries = params.entries(); + expect(entries[0][0]).toBe("foo"); + expect(entries[0][1]).toBe("1"); + + expect(entries[1][0]).toBe("bar"); + expect(entries[1][1]).toBe("2"); + + }); + + + it("Test URLSearchParams size", function(){ + const params = new URLSearchParams(fooBar); + expect(params.size).toBe(2); + }); + + it("Test URLSearchParams append", function(){ + const params = new URLSearchParams(fooBar); + params.append("first", "Osei"); + expect(params.get("first")).toBe("Osei"); + }); + + + it("Test URLSearchParams delete", function(){ + const params = new URLSearchParams(fooBar); + params.append("first", "Osei"); + params.delete("first"); + expect(params.get("first")).toBe(undefined); + }); + + + it("Test URLSearchParams has", function(){ + const params = new URLSearchParams(fooBar); + expect(params.has("foo")).toBe(true); + }); + + it("Test URLSearchParams changes propagates to URL parent", function(){ + const toBe = 'https://github.com/triniwiz?first=Osei'; + const url = new URL('https://github.com/triniwiz'); + const params = url.searchParams; + console.log(params); + params.set('first', 'Osei'); + expect(url.toString()).toBe(toBe); + }); + });