Skip to content

Commit d6b9753

Browse files
committed
test case fixed and test passed
1 parent 991180d commit d6b9753

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
12-
const rank = card.slice(0, -1); // Extract rank before the suit
11+
const rank = card.slice(0, -1); // Get everything except the last char (the suit)
1312

1413
if (rank === "A") {
1514
return 11;
@@ -18,10 +17,8 @@ function getCardValue(card) {
1817
} else if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) {
1918
return Number(rank);
2019
} else {
21-
throw new Error('Invalid card rank: "${rank}"'); //rather than just "Invalid card rank" we can show the actual rank that was invalid
20+
throw new Error(`Invalid card rank: "${rank}"`); // rather than just "Invalid card rank" we can show the actual rank that was invalid
2221
}
23-
24-
2522
}
2623

2724
// The line below allows us to load the getCardValue function into tests in other files.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ test("should return 11 for Ace (A)", () => {
2929
// Case 5: Handle Invalid Cards:
3030

3131
test("should throw an error for invalid input '1♣'", () => {
32-
expect(() => getCardValue("1♣")).toThrow("Invalid card");
32+
expect(() => getCardValue("1♣")).toThrow('Invalid card rank: "1"');
3333
});
3434

3535
test("should throw an error for invalid input '1♦'", () => {
36-
expect(() => getCardValue("1♦")).toThrow("Invalid card");
36+
expect(() => getCardValue("1♦")).toThrow('Invalid card rank: "1"');
3737
});
3838

3939
test("should throw an error for invalid input 'B♥'", () => {
40-
expect(() => getCardValue("B♥")).toThrow("Invalid card");
40+
expect(() => getCardValue("B♥")).toThrow('Invalid card rank: "B"');
4141
});
4242

4343
test("should throw an error for invalid input 'Z♠'", () => {
44-
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
44+
expect(() => getCardValue("Z♠")).toThrow('Invalid card rank: "Z"');
4545
});
4646

4747
test("should throw an error for empty string", () => {
48-
expect(() => getCardValue("")).toThrow("Invalid card");
48+
expect(() => getCardValue("")).toThrow('Invalid card rank: ""');
4949
});
5050

5151

0 commit comments

Comments
 (0)