Skip to content

Commit f6b6ecb

Browse files
authored
Add tests for card values and error handling
1 parent 3a4fd15 commit f6b6ecb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,25 @@ test(`Should return 11 when given an ace card`, () => {
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14+
test(`Should return the correct number for number cards`, () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("9♥")).toEqual(9);
17+
expect(getCardValue("10♦")).toEqual(10);
18+
});
1419
// Face Cards (J, Q, K)
20+
expect(getCardValue("J♣")).toEqual(10);
21+
expect(getCardValue("Q♦")).toEqual(10);
22+
expect(getCardValue("K♠")).toEqual(10);
23+
});
1524
// Invalid Cards
25+
test(`Should throw an error for invalid card strings`, () => {
26+
const invalidCards = ["", "A", "11♠", "1♠", "B♠", "10X", "♠A", "invalid"];
27+
28+
for (const badCard of invalidCards) {
29+
expect(() => getCardValue(badCard)).toThrowError();
30+
}
31+
});
32+
1633

1734
// To learn how to test whether a function throws an error as expected in Jest,
1835
// please refer to the Jest documentation:

0 commit comments

Comments
 (0)