File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 11function countChar ( stringOfCharacters , findCharacter ) {
2+ if ( arguments . length !== 2 ) {
3+ throw new Error (
4+ "Function requires exactly two arguments: a string and a character to find."
5+ ) ;
6+ }
27 if ( typeof stringOfCharacters !== 'string' ) {
38 throw new Error ( "First argument must be a string." ) ;
49 }
Original file line number Diff line number Diff line change @@ -103,3 +103,14 @@ test.each([
103103 countChar ( str , char ) ;
104104 } ) . toThrow ( error ) ;
105105} ) ;
106+ //test for 2 arguments
107+ test ( "should throw error if more/less than 2 arguments are provided" , ( ) => {
108+ expect ( ( ) => {
109+ countChar ( "hello" ) ;
110+ } ) . toThrow ( "Function requires exactly two arguments: a string and a character to find." ) ;
111+ expect ( ( ) => {
112+ countChar ( "hello" , "h" , "extra" ) ;
113+ } ) . toThrow (
114+ "Function requires exactly two arguments: a string and a character to find."
115+ ) ;
116+ } ) ;
You can’t perform that action at this time.
0 commit comments