-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathquerystring.test.js
More file actions
50 lines (42 loc) · 1.23 KB
/
querystring.test.js
File metadata and controls
50 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const parseQueryString = require("./querystring.js");
describe("parseQueryString()", () => {
test("parses querystring values containing =", () => {
expect(parseQueryString("equation=x=y+1")).toEqual({
equation: "x=y+1",
});
});
test("returns an empty object for an empty string", () => {
expect(parseQueryString("")).toEqual({});
});
test("parses a single key-value pair", () => {
expect(parseQueryString("name=Richard")).toEqual({
name: "Richard",
});
});
test("parses multiple key-value pairs", () => {
expect(parseQueryString("name=Richard&city=Sheffield")).toEqual({
name: "Richard",
city: "Sheffield",
});
});
test("handles a key with an empty value", () => {
expect(parseQueryString("name=")).toEqual({
name: "",
});
});
test("handles a key with no equals sign", () => {
expect(parseQueryString("name")).toEqual({
name: "",
});
});
test("ignores an empty trailing pair", () => {
expect(parseQueryString("name=Richard&")).toEqual({
name: "Richard",
});
});
test("decodes URL-encoded keys and values", () => {
expect(parseQueryString("tags%5B%5D=hello%20world")).toEqual({
"tags[]": "hello world",
});
});
});