-
-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathquerystring.test.js
More file actions
53 lines (46 loc) · 1.52 KB
/
querystring.test.js
File metadata and controls
53 lines (46 loc) · 1.52 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
51
// 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",
});
expect(parseQueryString("token=abc=123=xyz")).toEqual({
"token": "abc=123=xyz",
});
expect(parseQueryString("shop=myshop.myshopify.com")).toEqual({
"shop": "myshop.myshopify.com",
});
});
test("parses querystring values containing = and &", () => {
expect(parseQueryString("category=shoes&color=black&size=10")).toEqual({
category: "shoes", color: "black", size: "10"
});
expect(parseQueryString("page=2&limit=10")).toEqual({
page: "2", limit: "10"
});
});
test("parses querystring values containing +", () => {
expect(parseQueryString("q=javascript+array+methods")).toEqual({
q: "javascript+array+methods"
})
});
test("new tests", () => {
expect(parseQueryString("a=b&=&c=d")).toEqual({
a: "b", "": "", c: "d"
});
expect(parseQueryString("a=")).toEqual({
a: ""
});
expect(parseQueryString("=b")).toEqual({
"": "b"
});
expect(parseQueryString("a=b&&c=d")).toEqual({
a: "b", c: "d"
});
expect(parseQueryString("a%25b=c%26d")).toEqual({
"a%b": "c&d"
})
})