Skip to content

Commit 047df5d

Browse files
committed
Add jest .toThrow method for checking if the function can throw the expected error.
1 parent 1154f89 commit 047df5d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ test("should return 10 for King of Spades", () => {
3030
expect(kingofSpades).toEqual(10);
3131
});
3232

33-
try {
34-
getCardValue("Z♠");
35-
} catch (error) {
36-
console.log("Caught error:", error.message);
37-
}
33+
test("throws an error or invalid card", () => {
34+
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
35+
});
36+
37+
// try {
38+
// getCardValue("Z♠");
39+
//} catch (error) {
40+
// console.log("Caught error:", error.message);
41+
//}
3842

3943
// Case 2: Handle Number Cards (2-10):
4044
// Case 3: Handle Face Cards (J, Q, K):

0 commit comments

Comments
 (0)