|
3 | 3 | // Below is one test case for an edge case the implementation doesn't handle well.
|
4 | 4 | // Fix the implementation for this test, 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 |
| -test("parses querystring values containing =", () => { |
9 |
| - expect(parseQueryString("equation=x=y+1")).toEqual({ |
10 |
| - "equation": "x=y+1", |
| 8 | +describe("edge cases for parseQueryString function", () => { |
| 9 | + test("parses querystring values containing =", () => { |
| 10 | + expect(parseQueryString("equation=x=y+1")).toEqual({ |
| 11 | + equation: "x=y+1", |
| 12 | + }); |
| 13 | + }); |
| 14 | + |
| 15 | + test("parses querystring values containing '=' and additional whitespaces around '=' sign", () => { |
| 16 | + expect(parseQueryString("equation = x=y+1")).toEqual({ |
| 17 | + equation: "x=y+1", |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + test("parses empty querystring", () => { |
| 22 | + expect(parseQueryString("")).toEqual({}); |
| 23 | + }); |
| 24 | + |
| 25 | + test("parses querystring with duplicate keys", () => { |
| 26 | + expect(parseQueryString("equation=x&equation=y+1")).toEqual({ |
| 27 | + equation: "x", |
| 28 | + equation: "y+1", |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + test("parses querystring with leading or trailing &s", () => { |
| 33 | + expect(parseQueryString("&equation=x&")).toEqual({ |
| 34 | + equation: "x", |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + test("parses querystring with missing key", () => { |
| 39 | + expect(parseQueryString("=x")).toEqual({ |
| 40 | + "": "x", |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + test("parses querystring with missing value", () => { |
| 45 | + expect(parseQueryString("equation=")).toEqual({ |
| 46 | + equation: "", |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + test("parses querystring with missing '='", () => { |
| 51 | + expect(parseQueryString("equation&gh5")).toEqual({ |
| 52 | + equation: "", |
| 53 | + gh5: "", |
| 54 | + }); |
11 | 55 | });
|
12 | 56 | });
|
0 commit comments