Skip to content

Commit 31843b8

Browse files
committed
Update 3-get-card-value.test.js
Add Jest tests for Ace, number, face, and invalid cards for getCardValue.
1 parent 4b98073 commit 31843b8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@ test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
1111

12+
// Case 2: Number cards (2-10)
13+
test(`Should return the correct number for number cards`, () => {
14+
expect(getCardValue("2♠")).toEqual(2);
15+
expect(getCardValue("5♥")).toEqual(5);
16+
expect(getCardValue("10♦")).toEqual(10);
17+
});
18+
19+
// Case 3: Face cards (J, Q, K)
20+
test(`Should return 10 for face cards`, () => {
21+
expect(getCardValue("J♣")).toEqual(10);
22+
expect(getCardValue("Q♦")).toEqual(10);
23+
expect(getCardValue("K♥")).toEqual(10);
24+
});
25+
26+
// Case 4: Invalid cards
27+
test(`Should throw error for invalid cards`, () => {
28+
expect(() => getCardValue("1♠")).toThrow("Invalid card"); // invalid rank
29+
expect(() => getCardValue("A?")).toThrow("Invalid card"); // invalid suit
30+
expect(() => getCardValue("10♠♠")).toThrow("Invalid card"); // extra character
31+
expect(() => getCardValue("")).toThrow("Invalid card"); // empty string
32+
expect(() => getCardValue("banana")).toThrow("Invalid card"); // completely invalid
33+
});
34+
1235
// Suggestion: Group the remaining test data into these categories:
1336
// Number Cards (2-10)
1437
// Face Cards (J, Q, K)

0 commit comments

Comments
 (0)