Skip to content

Commit 094c32b

Browse files
authored
Enhance query string tests for edge cases
Added tests for handling empty query strings and decoding spaces.
1 parent 9413fa5 commit 094c32b

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎Sprint-2/implement/querystring.test.js‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,23 @@ test("should replace '+' by ' '", () => {
3737
});
3838
});
3939

40-
// Stretch exercise: Handling query strings that contain identical keys
40+
test("returns empty object for empty query", () => {
41+
expect(parseQueryString("")).toEqual({});
42+
});
43+
44+
test("ignores multiple empty pairs", () => {
45+
expect(parseQueryString("&&&&")).toEqual({});
46+
});
4147

42-
// Delete this test if you are not working on this optional case
43-
test("should store values of a key in an array when the key has 2 or more values", () => {
44-
expect(parseQueryString("key=value1&key=value2&key=value3&foo=bar")).toEqual({
45-
key: ["value1", "value2", "value3"],
46-
foo: "bar",
48+
test("decodes encoded spaces", () => {
49+
expect(parseQueryString("name=John%20Doe")).toEqual({
50+
name: "John Doe",
4751
});
4852
});
53+
54+
test("keeps all '=' in values", () => {
55+
expect(parseQueryString("expr=a=b=c=d")).toEqual({
56+
expr: "a=b=c=d",
57+
});
58+
});
59+

0 commit comments

Comments
 (0)