Skip to content

Commit 97a65d0

Browse files
authored
Refactor query string tests for clarity and correctness
1 parent 2bd72b8 commit 97a65d0

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
const parseQueryString = require("./querystring.js");
77

88
test("should parse values containing '='", () => {
9-
const input = "equation=a=b-2";
10-
const currentOutput = parseQueryString(input);
11-
const targetOutput = {
9+
expect(parseQueryString("equation=a=b-2")).toEqual({
1210
equation: "a=b-2",
13-
};
14-
15-
expect(currentOutput).toStrictEqual(targetOutput);
11+
});
1612
});
1713

1814
test("should ignore empty key-value pairs", () => {
1915
const input = "key1=value1&&key2=value2&";
16+
2017
const currentOutput = parseQueryString(input);
18+
2119
const targetOutput = {
2220
key1: "value1",
2321
key2: "value2",
2422
};
23+
2524
expect(currentOutput).toEqual(targetOutput);
2625
});
26+
2727
test("should accept empty string as key or as value", () => {
2828
expect(parseQueryString("=value")).toEqual({
2929
"": "value",
@@ -38,15 +38,6 @@ test("should accept empty string as key or as value", () => {
3838
});
3939
});
4040

41-
// test("should accept empty string as key or as value", () => {
42-
// const currentOutput = parseQueryString(input);
43-
// }
44-
// expect(currentOutput).toEqual(targetOutput);
45-
// expect(parseQueryString("=value")).toEqual({ "": "value" });
46-
// expect(parseQueryString("key")).toEqual({ key: "" });
47-
// expect(parseQueryString("key=")).toEqual({ key: "" });
48-
// expect(parseQueryString("=")).toEqual({ "": "" });
49-
5041
test("should decode percent-encoded characters", () => {
5142
expect(parseQueryString("%24half=1%2F2")).toEqual({
5243
$half: "1/2",
@@ -55,8 +46,13 @@ test("should decode percent-encoded characters", () => {
5546

5647
test("should replace '+' by ' '", () => {
5748
const input = "full+name=John+Doe";
49+
5850
const currentOutput = parseQueryString(input);
59-
const expectedOutput = { "full name": "John Doe" };
51+
52+
const expectedOutput = {
53+
"full name": "John Doe",
54+
};
55+
6056
expect(currentOutput).toEqual(expectedOutput);
6157
});
6258

@@ -65,7 +61,13 @@ test("should replace '+' by ' '", () => {
6561
// Delete this test if you are not working on this optional case
6662
// test("should store values of a key in an array when the key has 2 or more values", () => {
6763
// const input = "key=value1&key=value2&key=value3&foo=bar";
64+
6865
// const currentOutput = parseQueryString(input);
69-
// const expectedOutput = { key: ["value1", "value2", "value3"], foo: "bar" };
66+
67+
// const expectedOutput = {
68+
// key: ["value1", "value2", "value3"],
69+
// foo: "bar",
70+
// };
71+
7072
// expect(currentOutput).toEqual(expectedOutput);
7173
// });

0 commit comments

Comments
 (0)