-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); |