@@ -46,5 +46,56 @@ test("should return empty string if count is 0", () => {
4646test ( "should return error message for negative count" , ( ) => {
4747 const str = "hello" ;
4848 const count = - 2 ;
49- expect ( repeat ( str , count ) ) . toEqual ( "Count must be a non-negative integer" ) ;
50- } ) ;
49+ expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
50+ } ) ;
51+
52+ // invalid input tests
53+ test ( "should return error message for non-integer count" , ( ) => {
54+ const str = "hello" ;
55+ const count = 2.5 ;
56+ expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
57+ } ) ;
58+
59+ test ( "should return error message for non-string input" , ( ) => {
60+ const str = 123 ;
61+ const count = 3 ;
62+ expect ( repeat ( str , count ) ) . toEqual ( "First argument must be a string" ) ;
63+ } ) ;
64+
65+ test ( "should return error message for non-string input with invalid count" , ( ) => {
66+ const str = { text : "hello" } ;
67+ const count = - 2 ;
68+ expect ( repeat ( str , count ) ) . toEqual ( "First argument must be a string" ) ;
69+ } ) ;
70+
71+ test ( "should return error message for string input with non number count" , ( ) => {
72+ const str = "hello" ;
73+ const count = "3" ;
74+ const count2 = [ ] ;
75+ expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
76+ expect ( repeat ( str , count2 ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
77+ } ) ;
78+
79+ test ( "should return error message for string input with NaN count" , ( ) => {
80+ const str = "hello" ;
81+ const count = NaN ;
82+ expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
83+ } ) ;
84+
85+ test ( "should return error message for string input with null count" , ( ) => {
86+ const str = "hello" ;
87+ const count = null ;
88+ expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
89+ } ) ;
90+
91+ test ( "should return error message for string input with undefined count" , ( ) => {
92+ const str = "hello" ;
93+ const count = undefined ;
94+ expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
95+ } ) ;
96+
97+ test ( 'should have the correct amount of arguments' , ( ) => {
98+ expect ( repeat ( 'hello' ) ) . toEqual ( "Function requires exactly 2 arguments" ) ;
99+ expect ( repeat ( "hello" , 3 , 3 ) ) . toEqual ( "Function requires exactly 2 arguments" ) ;
100+ } )
101+
0 commit comments