Skip to content

Commit 24b90eb

Browse files
authored
Add tests for createLookup function
Added tests for createLookup function to verify correct handling of valid pairs, empty input, and malformed pairs.
1 parent 3e9f5b5 commit 24b90eb

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
const createLookup = require("./lookup.js");
22

3-
test.todo("creates a country currency code lookup for multiple codes");
3+
test("creates lookup object from pairs", () => {
4+
const pairs = [
5+
["US", "USD"],
6+
["CA", "CAD"],
7+
];
8+
const expected = { US: "USD", CA: "CAD" };
9+
expect(createLookup(pairs)).toEqual(expected);
10+
});
11+
12+
test("empty input returns empty object", () => {
13+
expect(createLookup([])).toEqual({});
14+
});
15+
16+
test("ignores malformed pairs and only maps valid 2-item arrays", () => {
17+
const pairs = [["GB", "GBP"], ["X"], null, ["FR", "EUR"]];
18+
const expected = { GB: "GBP", FR: "EUR" };
19+
expect(createLookup(pairs)).toEqual(expected);
20+
});
421

522
/*
623

0 commit comments

Comments
 (0)