Skip to content

Commit 3e9f5b5

Browse files
authored
Implement tests for tally function
1 parent c8c25c8 commit 3e9f5b5

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@ const tally = require("./tally.js");
2323
// Given an empty array
2424
// When passed to tally
2525
// Then it should return an empty object
26-
test.todo("tally on an empty array returns an empty object");
26+
test("tally on an empty array returns an empty object", () => {
27+
expect(tally([])).toEqual({});
28+
});
2729

2830
// Given an array with duplicate items
2931
// When passed to tally
3032
// Then it should return counts for each unique item
3133

34+
test("counts duplicates correctly", () => {
35+
expect(tally(["a"])).toEqual({ a: 1 });
36+
expect(tally(["a", "a", "a"]).a).toBe(3);
37+
expect(tally(["a", "a", "b", "c"])).toEqual({ a: 2, b: 1, c: 1 });
38+
});
39+
3240
// Given an invalid input like a string
3341
// When passed to tally
3442
// Then it should throw an error
43+
test("throws on invalid input", () => {
44+
expect(() => tally("not-an-array")).toThrow();
45+
expect(() => tally(null)).toThrow();
46+
});

0 commit comments

Comments
 (0)