Skip to content

Commit 74fdc0a

Browse files
Refactor tests for getCardValue function to improve structure and coverage for number and face cards, including error handling for invalid inputs
1 parent ca4d48e commit 74fdc0a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,34 @@ test(`Should return 11 when given an ace card`, () => {
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14+
15+
test(`Should return the correct value for number cards`, () => {
16+
expect(getCardValue("2♠")).toEqual(2);
17+
expect(getCardValue("3♠")).toEqual(3);
18+
expect(getCardValue("4♠")).toEqual(4);
19+
expect(getCardValue("5♠")).toEqual(5);
20+
expect(getCardValue("6♠")).toEqual(6);
21+
expect(getCardValue("7♠")).toEqual(7);
22+
expect(getCardValue("8♠")).toEqual(8);
23+
expect(getCardValue("9♠")).toEqual(9);
24+
expect(getCardValue("10♠")).toEqual(10);
25+
});
1426
// Face Cards (J, Q, K)
27+
test(`Should return 10 for face cards`, () => {
28+
expect(getCardValue("J♠")).toEqual(10);
29+
expect(getCardValue("Q♠")).toEqual(10);
30+
expect(getCardValue("K♠")).toEqual(10);
31+
});
1532
// Invalid Cards
33+
test(`Should throw an error for invalid cards`, () => {
34+
expect(() => getCardValue("1♠")).toThrow();
35+
expect(() => getCardValue("11♠")).toThrow();
36+
expect(() => getCardValue("B♠")).toThrow();
37+
expect(() => getCardValue("Z♠")).toThrow();
38+
expect(() => getCardValue("A")).toThrow();
39+
expect(() => getCardValue("10")).toThrow();
40+
});
1641

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

0 commit comments

Comments
 (0)