Skip to content

Commit ab9acf2

Browse files
committed
Rewrote tests for 3-get-card-value.test.js using Jest syntax
1 parent d4ace42 commit ab9acf2

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,35 @@ test(`Should return 11 when given an ace card`, () => {
1414
// Face Cards (J, Q, K)
1515
// Invalid Cards
1616

17+
// Case 2: Number Cards (2-10)
18+
test(`Should return correct value for single digit number card`, () => {
19+
expect(getCardValue("9♠")).toEqual(9);
20+
expect(getCardValue("5♦")).toEqual(5);
21+
expect(getCardValue("10♣")).toEqual(10);
22+
});
23+
24+
// Case 3: Face cards (J, Q, K)
25+
test(`Should return 10 for face cards (J, Q, K)`, () => {
26+
expect(getCardValue("J♥")).toEqual(10);
27+
expect(getCardValue("Q♦")).toEqual(10);
28+
expect(getCardValue("K♣")).toEqual(10);
29+
});
30+
31+
// Case 4: Invalid Cards
32+
test(`Should throw error for invalid cards`, () => {
33+
expect(() => getCardValue("invalid")).toThrow();
34+
// too short
35+
expect(() => getCardValue("A")).toThrow();
36+
// invalid rank
37+
expect(() => getCardValue("X♠")).toThrow();
38+
// invalid suit
39+
expect(() => getCardValue("Kx")).toThrow();
40+
// missing suit
41+
expect(() => getCardValue("10")).toThrow();
42+
// empty string
43+
expect(() => getCardValue("")).toThrow();
44+
});
45+
1746
// To learn how to test whether a function throws an error as expected in Jest,
1847
// please refer to the Jest documentation:
1948
// https://jestjs.io/docs/expect#tothrowerror
20-

0 commit comments

Comments
 (0)