Skip to content

Commit 8a9d777

Browse files
committed
Refactor tests for getCardValue function to improve structure and clarity
1 parent f0af80d commit 8a9d777

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@ const getCardValue = require("../implement/3-get-card-value");
55
// TODO: Write tests in Jest syntax to cover all possible outcomes.
66

77
// Case 1: Ace (A)
8-
test(`Should return 11 when given an ace card`, () => {
8+
test("Should return 11 when given an ace card", () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14+
test("should return correct value for number cards", () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("5♥")).toEqual(5);
17+
expect(getCardValue("9♦")).toEqual(9);
18+
expect(getCardValue("10♣")).toEqual(10);
19+
});
1420
// Face Cards (J, Q, K)
21+
test("should return 10 for face cards", () => {
22+
expect(getCardValue("J♠")).toEqual(10);
23+
expect(getCardValue("Q♥")).toEqual(10);
24+
expect(getCardValue("K♦")).toEqual(10);
25+
});
26+
1527
// Invalid Cards
28+
test("should throw an error for invalid cards", () => {
29+
expect(() => getCardValue("1♠")).toThrow();
30+
expect(() => getCardValue("Z♣")).toThrow();
31+
expect(() => getCardValue("A")).toThrow(); // missing suit
32+
expect(() => getCardValue("")).toThrow(); // empty string
33+
});
1634

1735
// To learn how to test whether a function throws an error as expected in Jest,
1836
// please refer to the Jest documentation:
1937
// https://jestjs.io/docs/expect#tothrowerror
20-

0 commit comments

Comments
 (0)