forked from CodeYourFuture/Module-Data-Groups
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquerystring.test.js
More file actions
32 lines (26 loc) · 1.17 KB
/
querystring.test.js
File metadata and controls
32 lines (26 loc) · 1.17 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
// 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("parseQueryString receives an empty string", () => {
expect(parseQueryString("")).toEqual({});
});
test("parses querystring values containing =", () => {
expect(parseQueryString("equation=x=y+1")).toEqual({
equation: "x=y+1",
});
});
test("if our function is passed only one key - value pair", () => {
expect(parseQueryString("color=brown")).toEqual({ color: "brown" });
});
test("parses querystring without an =, it should throw an error", () => {
expect(() => parseQueryString("colorisequaltobrown")).toThrow(
"error invalid format string, no = to separate key value pairs"
);
});
test("if our function is passed only one string but there is no =", () => {
expect(() => parseQueryString("color,brown")).toThrow(
"error invalid format string, no = to separate key value pair"
);
});