-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathquerystring.test.js
More file actions
41 lines (35 loc) · 1.21 KB
/
querystring.test.js
File metadata and controls
41 lines (35 loc) · 1.21 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
// In the prep, we implemented a function to parse query strings.
// Unfortunately, it contains several bugs!
// Below is one test case for an edge case the implementation doesn't handle well.
// Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too.
const parseQueryString = require("./querystring.js");
test("parses querystring values containing =", () => {
expect(parseQueryString("equation=x=y+1")).toEqual({
equation: "x=y+1",
});
});
test("parses querystring values containing repetitive keys", () => {
expect(parseQueryString("a=1&b=6&a=2&a=3&b=7")).toEqual({
a: ["1", "2", "3"],
b: ["6", "7"],
});
});
test("parses querystring values containing repetitive keys with same values", () => {
expect(parseQueryString("a=1&b=6&a=2&a=3&b=6")).toEqual({
a: ["1", "2", "3"],
b: "6",
});
});
test("parses querystring values containing no key and value but only =", () => {
expect(parseQueryString("=&b=6&a=2&=&=")).toEqual({
a: "2",
b: "6",
});
});
test("parses querystring values missing = sign", () => {
expect(parseQueryString("id=5&name=mohsen&age")).toEqual({
id: "5",
name: "mohsen",
age: "",
});
});