Skip to content

Commit 91ced4e

Browse files
committed
modified case 5 handle invalid cards
1 parent db40788 commit 91ced4e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,28 @@ test("should return 11 for Ace (A)", () => {
2727
expect(getCardValue("A♥")).toEqual(11);
2828
});
2929
// Case 5: Handle Invalid Cards:
30-
test("should return null for invalid cards", () => {
31-
expect(getCardValue("1♣")).toBeNull();
32-
expect(getCardValue("11♦")).toBeNull();
33-
expect(getCardValue("B♥")).toBeNull();
34-
expect(getCardValue("Z♠")).toBeNull();
30+
31+
test("should throw an error for invalid input '1♣'", () => {
32+
expect(() => getCardValue("1♣")).toThrow("Invalid card");
33+
});
34+
35+
test("should throw an error for invalid input '1♦'", () => {
36+
expect(() => getCardValue("1♦")).toThrow("Invalid card");
37+
});
38+
39+
test("should throw an error for invalid input 'B♥'", () => {
40+
expect(() => getCardValue("B♥")).toThrow("Invalid card");
3541
});
3642

43+
test("should throw an error for invalid input 'Z♠'", () => {
44+
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
45+
});
46+
47+
test("should throw an error for empty string", () => {
48+
expect(() => getCardValue("")).toThrow("Invalid card");
49+
});
50+
51+
3752
// We can run this test file using the command `npx jest 3-get-card-value.test.js`
3853
// in the terminal. Making sure we are in the directory where this file is located.
3954
// If we have Jest installed globally, you can simply run `3-get-card-value.test.js`

0 commit comments

Comments
 (0)