|
1 | 1 | describe("Test URLSearchParams ", function () { |
2 | | - |
3 | | - |
4 | | -it("Test URLSearchParams keys", function(){ |
5 | | -const params = new URLSearchParams("foo=1&bar=2"); |
6 | | -const keys = params.keys(); |
7 | | -expect(keys[0]).toBe("foo"); |
8 | | -expect(keys[1]).toBe("bar"); |
9 | | -}); |
10 | | - |
11 | | -it("Test URLSearchParams values", function(){ |
12 | | -const params = new URLSearchParams("foo=1&bar=2"); |
13 | | -const values = params.values(); |
14 | | -expect(values[0]).toBe("1"); |
15 | | -expect(values[1]).toBe("2"); |
16 | | -}); |
17 | | - |
18 | | - |
19 | | -it("Test URLSearchParams entries", function(){ |
20 | | -const params = new URLSearchParams("foo=1&bar=2"); |
21 | | -const entries = params.entries(); |
22 | | -expect(entries[0][0]).toBe("foo"); |
23 | | -expect(entries[0][1]).toBe("1"); |
24 | | - |
25 | | -expect(entries[1][0]).toBe("bar"); |
26 | | -expect(entries[1][1]).toBe("2"); |
27 | | - |
28 | | -}); |
29 | | - |
30 | | - |
31 | | -it("Test URLSearchParams size", function(){ |
32 | | -const params = new URLSearchParams("foo=1&bar=2"); |
33 | | -expect(params.size).toBe(2); |
34 | | -}); |
35 | | - |
36 | | -it("Test URLSearchParams append", function(){ |
37 | | -const params = new URLSearchParams("foo=1&bar=2"); |
38 | | -params.append("first", "Osei"); |
39 | | -expect(params.get("first")).toBe("Osei"); |
40 | | -}); |
41 | | - |
42 | | - |
43 | | -it("Test URLSearchParams delete", function(){ |
44 | | -const params = new URLSearchParams("foo=1&bar=2"); |
45 | | -params.append("first", "Osei"); |
46 | | -params.delete("first"); |
47 | | -expect(params.get("first")).toBe(undefined); |
48 | | -}); |
49 | | - |
50 | | - |
51 | | -it("Test URLSearchParams has", function(){ |
52 | | -const params = new URLSearchParams("foo=1&bar=2"); |
53 | | -expect(params.has("foo")).toBe(true); |
54 | | -}); |
55 | | - |
| 2 | + const fooBar = "foo=1&bar=2"; |
| 3 | + it("Test URLSearchParams keys", function(){ |
| 4 | + const params = new URLSearchParams(fooBar); |
| 5 | + const keys = params.keys(); |
| 6 | + expect(keys[0]).toBe("foo"); |
| 7 | + expect(keys[1]).toBe("bar"); |
| 8 | + }); |
| 9 | + |
| 10 | + it("Test URLSearchParams values", function(){ |
| 11 | + const params = new URLSearchParams(fooBar); |
| 12 | + const values = params.values(); |
| 13 | + expect(values[0]).toBe("1"); |
| 14 | + expect(values[1]).toBe("2"); |
| 15 | + }); |
| 16 | + |
| 17 | + |
| 18 | + it("Test URLSearchParams entries", function(){ |
| 19 | + const params = new URLSearchParams(fooBar); |
| 20 | + const entries = params.entries(); |
| 21 | + expect(entries[0][0]).toBe("foo"); |
| 22 | + expect(entries[0][1]).toBe("1"); |
| 23 | + |
| 24 | + expect(entries[1][0]).toBe("bar"); |
| 25 | + expect(entries[1][1]).toBe("2"); |
| 26 | + |
| 27 | + }); |
| 28 | + |
| 29 | + |
| 30 | + it("Test URLSearchParams size", function(){ |
| 31 | + const params = new URLSearchParams(fooBar); |
| 32 | + expect(params.size).toBe(2); |
| 33 | + }); |
| 34 | + |
| 35 | + it("Test URLSearchParams append", function(){ |
| 36 | + const params = new URLSearchParams(fooBar); |
| 37 | + params.append("first", "Osei"); |
| 38 | + expect(params.get("first")).toBe("Osei"); |
| 39 | + }); |
| 40 | + |
| 41 | + |
| 42 | + it("Test URLSearchParams delete", function(){ |
| 43 | + const params = new URLSearchParams(fooBar); |
| 44 | + params.append("first", "Osei"); |
| 45 | + params.delete("first"); |
| 46 | + expect(params.get("first")).toBe(undefined); |
| 47 | + }); |
| 48 | + |
| 49 | + |
| 50 | + it("Test URLSearchParams has", function(){ |
| 51 | + const params = new URLSearchParams(fooBar); |
| 52 | + expect(params.has("foo")).toBe(true); |
| 53 | + }); |
| 54 | + |
| 55 | + it("Test URLSearchParams changes propagates to URL parent", function(){ |
| 56 | + const toBe = 'https://github.com/triniwiz?first=Osei'; |
| 57 | + const url = new URL('https://github.com/triniwiz'); |
| 58 | + const params = url.searchParams; |
| 59 | + console.log(params); |
| 60 | + params.set('first', 'Osei'); |
| 61 | + expect(url.toString()).toBe(toBe); |
| 62 | + }); |
| 63 | + |
56 | 64 | }); |
0 commit comments