@@ -43,15 +43,42 @@ test("should return 11 for Ace of Hearts", () => {
4343 expect ( aceOfHearts ) . toEqual ( 11 ) ;
4444} ) ;
4545// Case 5: Handle Invalid Cards:
46+ const errorMessage =
47+ "Error: Invalid card rank. Input should be a string in the format 'R♠', where R is 2-10, J, Q, K, or A, followed by either ♠, ♥, ♦, or ♣." ;
48+
4649test ( "should throw an error for invalid card rank" , ( ) => {
4750 const invalidCard = getCardValue ( "1♠" ) ;
48- expect ( invalidCard ) . toEqual ( "Error: Invalid card rank" ) ;
51+ expect ( invalidCard ) . toEqual ( errorMessage ) ;
4952} ) ;
5053test ( "should throw an error for another invalid card rank" , ( ) => {
5154 const anotherInvalidCard = getCardValue ( "Z♠" ) ;
52- expect ( anotherInvalidCard ) . toEqual ( "Error: Invalid card rank" ) ;
55+ expect ( anotherInvalidCard ) . toEqual ( errorMessage ) ;
5356} ) ;
5457test ( "should throw an error for empty card string" , ( ) => {
5558 const emptyCard = getCardValue ( "" ) ;
56- expect ( emptyCard ) . toEqual ( "Error: Invalid card rank" ) ;
59+ expect ( emptyCard ) . toEqual ( errorMessage ) ;
60+ } ) ;
61+ test ( "should throw an error for boolean (true) input" , ( ) => {
62+ const booleanCard = getCardValue ( true ) ;
63+ expect ( booleanCard ) . toEqual ( errorMessage ) ;
64+ } ) ;
65+ test ( "should throw an error for boolean (false) input" , ( ) => {
66+ const booleanCard = getCardValue ( false ) ;
67+ expect ( booleanCard ) . toEqual ( errorMessage ) ;
68+ } ) ;
69+ test ( "should throw an error for numeric input" , ( ) => {
70+ const numericCard = getCardValue ( 10 ) ;
71+ expect ( numericCard ) . toEqual ( errorMessage ) ;
72+ } ) ;
73+ test ( "should throw an error for null input" , ( ) => {
74+ const nullCard = getCardValue ( null ) ;
75+ expect ( nullCard ) . toEqual ( errorMessage ) ;
76+ } ) ;
77+ test ( "should throw an error for undefined input" , ( ) => {
78+ const undefinedCard = getCardValue ( undefined ) ;
79+ expect ( undefinedCard ) . toEqual ( errorMessage ) ;
80+ } ) ;
81+ test ( "should throw an error for object input" , ( ) => {
82+ const objectCard = getCardValue ( { rank : "A" , suit : "♠" } ) ;
83+ expect ( objectCard ) . toEqual ( errorMessage ) ;
5784} ) ;
0 commit comments