@@ -45,7 +45,7 @@ test("should return an empty string when count is 0", () => {
4545test ( "should throw an error when count is negative" , ( ) => {
4646 const str = "hello" ;
4747 const count = - 2 ;
48- expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Invalid data value " ) ;
48+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Count should be a positive number " ) ;
4949} ) ;
5050
5151// case: str is not a string:
@@ -96,8 +96,15 @@ test("should return an empty string when str is an empty string", () => {
9696// Given invalid types for both str (e.g., an object) and count (e.g., an array),
9797// When the repeat function is called with these inputs,
9898// Then it should throw an error or return an appropriate error message, indicating that the input types are not supported.
99- test ( "should throw an error when str and count are of invalid types " , ( ) => {
99+ test ( "should throw an error when str is invalid type " , ( ) => {
100100 const str = { text : "hello" } ;
101- const count = [ 3 ] ;
102- expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Invalid data value" ) ;
101+ const count = 3 ;
102+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Input should be a string" ) ;
103+ } ) ;
104+
105+ // case: for throw error
106+ test ( "should throw an error when count is an array" , ( ) => {
107+ const str = "hello" ;
108+ const count = [ 2 ] ;
109+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Count should be a number" ) ;
103110} ) ;
0 commit comments