@@ -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