Skip to content

Commit 0c5244f

Browse files
Complete card value jest tests
1 parent c83572d commit 0c5244f

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
import { getCardValue } from "../implement/3-get-card-value.js";
22

3-
test("Should return 2 for a number card", () => {
3+
test("Should return the correct value for number cards", () => {
44
expect(getCardValue("2♥")).toEqual(2);
5-
});
6-
7-
test("Number card (2-10)", () => {
8-
expect(getCardValue("7♦")).toEqual(7);
5+
expect(getCardValue("3♠")).toEqual(3);
96
expect(getCardValue("4♣")).toEqual(4);
7+
expect(getCardValue("5♦")).toEqual(5);
8+
expect(getCardValue("6♥")).toEqual(6);
9+
expect(getCardValue("7♦")).toEqual(7);
10+
expect(getCardValue("8♣")).toEqual(8);
11+
expect(getCardValue("9♠")).toEqual(9);
12+
expect(getCardValue("10♥")).toEqual(10);
1013
});
1114

12-
test("Face Cards (J, Q, K)", () => {
15+
test("Should return 10 for face cards", () => {
1316
expect(getCardValue("J♣")).toEqual(10);
1417
expect(getCardValue("Q♦")).toEqual(10);
1518
expect(getCardValue("K♥")).toEqual(10);
1619
});
1720

18-
// Case 1: Ace (A)
19-
test(`Should return 11 when given an ace card`, () => {
21+
test("Should return 11 for an ace of any suit", () => {
2022
expect(getCardValue("A♠")).toEqual(11);
23+
expect(getCardValue("A♥")).toEqual(11);
24+
expect(getCardValue("A♦")).toEqual(11);
25+
expect(getCardValue("A♣")).toEqual(11);
26+
});
27+
28+
test("Should throw an error for an invalid rank", () => {
29+
expect(() => getCardValue("X♠")).toThrow(
30+
'Expected a number followed by a suit, but got "X♠"'
31+
);
32+
});
33+
34+
test("Should throw an error for an invalid suit", () => {
35+
expect(() => getCardValue("9x")).toThrow(
36+
'Expected a number followed by a suit, but got "9x"'
37+
);
2138
});
2239

23-
test("Invalid cards throw an error", () => {
24-
expect(() => getCardValue("2x")).toThrow();
25-
expect(() => getCardValue(invalid)).toThrow();
40+
test("Should throw an error for malformed input", () => {
41+
expect(() => getCardValue("invalid")).toThrow(
42+
'Expected a number followed by a suit, but got "invalid"'
43+
);
2644
});
2745

2846
// Suggestion: Group the remaining test data into these categories:

0 commit comments

Comments
 (0)