Skip to content

Commit 4bec805

Browse files
committed
test: rewrite and expand tests for getCardValue function with success and error cases
1 parent 7d6cba2 commit 4bec805

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ const getCardValue = require("../implement/3-get-card-value");
44

55
// TODO: Write tests in Jest syntax to cover all possible outcomes.
66

7-
// Case 1: Ace (A)
8-
test(`Should return 11 when given an ace card`, () => {
9-
expect(getCardValue("A♠")).toEqual(11);
10-
});
11-
127
// Suggestion: Group the remaining test data into these categories:
138
// Number Cards (2-10)
149
// Face Cards (J, Q, K)
@@ -18,3 +13,43 @@ test(`Should return 11 when given an ace card`, () => {
1813
// please refer to the Jest documentation:
1914
// https://jestjs.io/docs/expect#tothrowerror
2015

16+
describe("getCardValue", () => {
17+
18+
// Group 1: success cases (Valid cards)
19+
test("should return 11 when given an Ace (A)", () => {
20+
expect(getCardValue("A♠")).toBe(11);
21+
expect(getCardValue("A♥")).toBe(11);
22+
});
23+
24+
test("should return 10 when given a face card (J, Q, K)", () => {
25+
expect(getCardValue("J♣")).toBe(10);
26+
expect(getCardValue("Q♦")).toBe(10);
27+
expect(getCardValue("K♠")).toBe(10);
28+
});
29+
30+
test("should return the numeric value for number cards (2-10)", () => {
31+
expect(getCardValue("2♥")).toBe(2);
32+
expect(getCardValue("7♦")).toBe(7);
33+
expect(getCardValue("10♣")).toBe(10);
34+
});
35+
36+
// Group 2: error cases (Invalid cards)
37+
describe("Invalid cards", () => {
38+
test("should throw an error for invalid card length or missing components", () => {
39+
expect(() => getCardValue("A")).toThrow("Invalid card");
40+
expect(() => getCardValue("100♥")).toThrow("Invalid card");
41+
expect(() => getCardValue("")).toThrow("Invalid card");
42+
});
43+
44+
test("should throw an error for an invalid suit emoji", () => {
45+
expect(() => getCardValue("A🌸")).toThrow("Invalid card suit");
46+
expect(() => getCardValue("10X")).toThrow("Invalid card suit");
47+
});
48+
49+
test("should throw an error for an invalid rank", () => {
50+
expect(() => getCardValue("1♥")).toThrow("Invalid card rank");
51+
expect(() => getCardValue("15♦")).toThrow("Invalid card rank");
52+
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank");
53+
});
54+
});
55+
});

0 commit comments

Comments
 (0)