Skip to content

Commit 80e153e

Browse files
committed
card value
1 parent 442f828 commit 80e153e

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

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

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,60 @@
33
const getCardValue = require("../implement/3-get-card-value");
44

55

6+
67
// TODO: Write tests in Jest syntax to cover all possible outcomes.
78

89

10+
911
// Case 1: Ace (A)
10-
test(`Should return 11 when given an ace card`, () => {
12+
test("should return 11 for any ace (all suits)", () => {
1113
expect(getCardValue("A♠")).toEqual(11);
14+
expect(getCardValue("A♥")).toEqual(11);
15+
expect(getCardValue("A♦")).toEqual(11);
16+
expect(getCardValue("A♣")).toEqual(11);
1217
});
1318

1419

20+
1521
// Suggestion: Group the remaining test data into these categories:
1622
// Number Cards (2-10)
1723
// Face Cards (J, Q, K)
1824
// Invalid Cards
1925

2026

27+
2128
// To learn how to test whether a function throws an error as expected in Jest,
2229
// please refer to the Jest documentation:
2330
// [https://jestjs.io/docs/expect#tothrowerror](https://jestjs.io/docs/expect#tothrowerror)
2431

2532

26-
// Number Cards (2–10)
27-
test(`Should return 2 when given "2♦"`, () => {
28-
expect(getCardValue("2♦")).toEqual(2);
29-
});
30-
31-
test(`Should return 5 when given "5♣"`, () => {
32-
expect(getCardValue("5♣")).toEqual(5);
33-
});
3433

35-
test(`Should return 10 when given "10♥"`, () => {
34+
// Number Cards (2–10)
35+
test("should return the numeric value of number cards (2-10)", () => {
36+
expect(getCardValue("2♣")).toEqual(2);
37+
expect(getCardValue("5♠")).toEqual(5);
3638
expect(getCardValue("10♥")).toEqual(10);
39+
// Loop to verify all values 2–10 across one suit
40+
for (let n = 2; n <= 10; n++) {
41+
expect(getCardValue(`${n}♠`)).toEqual(n);
42+
}
3743
});
3844

3945

46+
4047
// Face Cards (J, Q, K)
41-
test(`Should return 10 when given "J♣"`, () => {
48+
test("should return 10 for all face cards (J, Q, K)", () => {
4249
expect(getCardValue("J♣")).toEqual(10);
43-
});
44-
45-
test(`Should return 10 when given "Q♦"`, () => {
4650
expect(getCardValue("Q♦")).toEqual(10);
47-
});
48-
49-
test(`Should return 10 when given "K♥"`, () => {
5051
expect(getCardValue("K♥")).toEqual(10);
5152
});
5253

5354

54-
// Invalid Cards
55-
test(`Should throw an error when given an invalid card symbol like "Z♠"`, () => {
56-
expect(() => getCardValue("Z♠")).toThrowError();
57-
});
5855

59-
test(`Should throw an error when given an empty string`, () => {
60-
expect(() => getCardValue("")).toThrowError();
56+
// Invalid Cards
57+
test("should throw an error for invalid cards", () => {
58+
expect(() => getCardValue("Z♠")).toThrow();
59+
expect(() => getCardValue("")).toThrow();
60+
expect(() => getCardValue(null)).toThrow();
6161
});
6262

63-
test(`Should throw an error when given null`, () => {
64-
expect(() => getCardValue(null)).toThrowError();
65-
});

0 commit comments

Comments
 (0)