22// We will use the same function, but write tests for it using Jest in this file.
33const getCardValue = require ( "../implement/3-get-card-value" ) ;
44
5-
6- // Case 1: Ace (A)
5+ // Ace (A)
76test ( `Should return 11 when given an ace card` , ( ) => {
87 expect ( getCardValue ( "A♠" ) ) . toEqual ( 11 ) ;
98} ) ;
109
11- // Suggestion: Group the remaining test data into these categories: // ♠ ♥ ♦ ♣
1210// Number Cards (2-10)
13- test ( `Should return the card's numeric rank for cards 2 through 10` , ( ) => {
11+ test ( `Should return the card's numeric rank for cards 2 through 10` , ( ) => {
1412 expect ( getCardValue ( "2♠" ) ) . toEqual ( 2 ) ;
1513 expect ( getCardValue ( "3♥" ) ) . toEqual ( 3 ) ;
1614 expect ( getCardValue ( "4♦" ) ) . toEqual ( 4 ) ;
@@ -20,26 +18,22 @@ test(`Should return the card's numeric rank for cards 2 through 10`, () =>{
2018 expect ( getCardValue ( "8♦" ) ) . toEqual ( 8 ) ;
2119 expect ( getCardValue ( "9♣" ) ) . toEqual ( 9 ) ;
2220 expect ( getCardValue ( "10♠" ) ) . toEqual ( 10 ) ;
21+ } ) ;
2322
24- } )
2523// Face Cards (J, Q, K)
2624test ( `should return 10 When the card is a face card ("J", "Q", "K")` , ( ) => {
2725 expect ( getCardValue ( "j♠" ) ) . toEqual ( 10 ) ;
2826 expect ( getCardValue ( "k♦" ) ) . toEqual ( 10 ) ;
2927 expect ( getCardValue ( "q♣" ) ) . toEqual ( 10 ) ;
28+ } ) ;
3029
31- } )
3230// Invalid Cards
3331test ( "should throw an error when an invalid card is played" , ( ) => {
3432 expect ( ( ) => getCardValue ( "" ) ) . toThrow ( "No card was played" ) ;
35- expect ( ( ) => getCardValue ( "1009♣" ) ) . toThrow ( "Invalid card played, rank and suit cannot be less " +
36- "than 1 or more than 3" )
37-
33+ expect ( ( ) => getCardValue ( "X♠" ) ) . toThrow (
34+ "Invalid card: rank is not recognised"
35+ ) ;
36+ expect ( ( ) => getCardValue ( "9X" ) ) . toThrow (
37+ "Invalid card: suit is not recognised"
38+ ) ;
3839} ) ;
39-
40-
41-
42- // To learn how to test whether a function throws an error as expected in Jest,
43- // please refer to the Jest documentation:
44- // https://jestjs.io/docs/expect#tothrowerror
45-
0 commit comments