|
3 | 3 | // Below are some test cases the implementation doesn't handle well. |
4 | 4 | // Fix the implementation for these tests, and try to think of as many other edge cases as possible - write tests and fix those too. |
5 | 5 |
|
6 | | -const parseQueryString = require("./querystring.js") |
| 6 | +const parseQueryString = require("./querystring.js"); |
7 | 7 |
|
8 | 8 | test("should parse values containing '='", () => { |
9 | 9 | expect(parseQueryString("equation=a=b-2")).toEqual({ |
@@ -37,12 +37,15 @@ test("should replace '+' by ' '", () => { |
37 | 37 | }); |
38 | 38 | }); |
39 | 39 |
|
| 40 | +test("should delete accidental '?' if first char by accident", () => { |
| 41 | + expect(parseQueryString("?colour=teal")).toEqual({ colour: "teal" }); |
| 42 | +}); |
40 | 43 | // Stretch exercise: Handling query strings that contain identical keys |
41 | 44 |
|
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", |
47 | | - }); |
48 | | -}); |
| 45 | +// // Delete this test if you are not working on this optional case |
| 46 | +// test("should store values of a key in an array when the key has 2 or more values", () => { |
| 47 | +// expect(parseQueryString("key=value1&key=value2&key=value3&foo=bar")).toEqual({ |
| 48 | +// key: ["value1", "value2", "value3"], |
| 49 | +// foo: "bar", |
| 50 | +// }); |
| 51 | +// }); |
0 commit comments