Skip to content

Commit ae41393

Browse files
committed
test throw error is written and test passed
1 parent cfd0d48 commit ae41393

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { getCardValue } from "../implement/3-get-card-value.js";
22

3-
// TODO: Write tests in Jest syntax to cover all possible outcomes.
4-
5-
// Case 1: Ace (A)
63
test(`Should return 11 when given an ace card`, () => {
74
expect(getCardValue("A♠")).toEqual(11);
85
});
@@ -14,14 +11,35 @@ test(`should retun the numeric value when given "numbered" cards`, () => {
1411
test(`should retun 10 when given(J,Q,K)cards`, () => {
1512
expect(getCardValue("J♣")).toEqual(10);
1613
expect(getCardValue("Q♥")).toEqual(10);
17-
1814
expect(getCardValue("K♦")).toEqual(10);
1915
});
16+
2017
test(`throws for invalid cards`, () => {
2118
expect(() => {
2219
getCardValue("invalid");
2320
}).toThrow(`Expected a number followed by a suit, but got "invalid"`);
2421
});
22+
test(`throws for invalid rank`, () => {
23+
expect(() => {
24+
getCardValue("1♥");
25+
}).toThrow(`Expected a valid Rank and suit instead got "1♥"`);
26+
});
27+
test(`throws for invalid suit`, () => {
28+
expect(() => {
29+
getCardValue("AS");
30+
}).toThrow(`Expected a valid Rank and suit instead got "AS"`);
31+
});
32+
test(`throws for invalid input`, () => {
33+
expect(() => {
34+
getCardValue("100");
35+
}).toThrow(`Expected a valid Rank and suit instead got "100"`);
36+
});
37+
test(`throws for invalid suit`, () => {
38+
expect(() => {
39+
getCardValue("15♥");
40+
}).toThrow(`Expected a valid Rank and suit instead got "15♥"`);
41+
});
42+
2543
// Suggestion: Group the remaining test data into these categories:
2644
// Number Cards (2-10)
2745
// Face Cards (J, Q, K)

0 commit comments

Comments
 (0)