Skip to content

Commit 720be29

Browse files
authored
Update tally.test.js
1 parent 2d7c3ad commit 720be29

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,30 @@ const tally = require("./tally.js");
1919
// Given a function called tally
2020
// When passed an array of items
2121
// Then it should return an object containing the count for each unique item
22+
test("returns counts for each unique item", () => {
23+
expect(tally(["a"])).toEqual({ a: 1 });
24+
expect(tally(["a", "b", "c"])).toEqual({ a: 1, b: 1, c: 1 });
25+
});
2226

2327
// Given an empty array
2428
// When passed to tally
2529
// Then it should return an empty object
26-
test.todo("tally on an empty array returns an empty object");
30+
test("tally on an empty array returns an empty object", () => {
31+
expect(tally([])).toEqual({});
32+
});
2733

2834
// Given an array with duplicate items
2935
// When passed to tally
3036
// Then it should return counts for each unique item
37+
test("returns counts for each unique item", () => {
38+
expect(tally(["a", "a", "a"])).toEqual({ a: 3 });
39+
expect(tally(["a", "a", "b", "c"])).toEqual({ a: 2, b: 1, c: 1 });
40+
});
3141

3242
// Given an invalid input like a string
3343
// When passed to tally
3444
// Then it should throw an error
45+
test("throws an error when passed an invalid input like a string", () => {
46+
expect(() => tally("string")).toThrow(TypeError);
47+
expect(() => tally("string")).toThrow("Expected an array as input");
48+
});

0 commit comments

Comments
 (0)