@@ -4,17 +4,58 @@ const getCardValue = require("../implement/3-get-card-value");
44
55// TODO: Write tests in Jest syntax to cover all possible outcomes.
66
7- // Case 1: Ace (A)
7+ // Case 1: Ace (A) ♣ ♦ ♥ C
88test ( `Should return 11 when given an ace card` , ( ) => {
99 expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
10+ expect ( getCardValue ( "A♥" ) ) . toEqual ( 11 ) ;
11+ expect ( getCardValue ( "A♦" ) ) . toEqual ( 11 ) ;
12+ expect ( getCardValue ( "A♣" ) ) . toEqual ( 11 ) ;
1013} ) ;
1114
15+
16+
1217// Suggestion: Group the remaining test data into these categories:
1318// Number Cards (2-10)
1419// Face Cards (J, Q, K)
1520// Invalid Cards
1621
22+
1723// To learn how to test whether a function throws an error as expected in Jest,
1824// please refer to the Jest documentation:
1925// https://jestjs.io/docs/expect#tothrowerror
2026
27+
28+ // Number cards
29+ test ( `Should return the number when given a number card` , ( ) => {
30+ expect ( getCardValue ( "2♠" ) ) . toEqual ( 2 ) ;
31+ expect ( getCardValue ( "7♥" ) ) . toEqual ( 7 ) ;
32+ expect ( getCardValue ( "9♦" ) ) . toEqual ( 9 ) ;
33+ expect ( getCardValue ( "6♣" ) ) . toEqual ( 6 ) ;
34+ } ) ;
35+
36+
37+ // Face Cards (J, Q, K)
38+ test ( `Should return 10 when given a face card` , ( ) => {
39+ expect ( getCardValue ( "J♠" ) ) . toEqual ( 10 ) ;
40+ expect ( getCardValue ( "Q♥" ) ) . toEqual ( 10 ) ;
41+ expect ( getCardValue ( "K♦" ) ) . toEqual ( 10 ) ;
42+ } ) ;
43+
44+
45+ // test(`Should throw an error when given an invalid card`, () => {
46+ // expect(() => getCardValue("1♠")).toThrow();
47+ // expect(() => getCardValue("Z♦")).toThrow();
48+ // expect(() => getCardValue("11♥")).toThrow();
49+ // expect(() => getCardValue("")).toThrow();
50+ // });
51+
52+ // Invalid Cards
53+ test ( `Should throw an error when given an invalid card` , ( ) => {
54+ expect ( ( ) => getCardValue ( "1♣" ) ) . toThrow ( "Invalid Card" ) ;
55+ expect ( ( ) => getCardValue ( "Z♦" ) ) . toThrow ( "Invalid Card" ) ;
56+ expect ( ( ) => getCardValue ( "12♦" ) ) . toThrow ( "Invalid Card" ) ;
57+ expect ( ( ) => getCardValue ( "♦3" ) ) . toThrow ( "Invalid Card" ) ;
58+ expect ( ( ) => getCardValue ( "" ) ) . toThrow ( "Invalid Card" ) ;
59+ expect ( ( ) => getCardValue ( "invalid" ) ) . toThrow ( "Invalid Card" ) ;
60+ expect ( ( ) => getCardValue ( "----" ) ) . toThrow ( "Invalid Card" ) ;
61+ } ) ;
0 commit comments