@@ -46,56 +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 ( "Second argument must be a non-negative integer" ) ;
49+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Second argument must be a non-negative integer" ) ;
5050} ) ;
5151
5252// invalid input tests
5353test ( "should return error message for non-integer count" , ( ) => {
5454 const str = "hello" ;
5555 const count = 2.5 ;
56- expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
56+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Second argument must be a non-negative integer" ) ;
5757} ) ;
5858
5959test ( "should return error message for non-string input" , ( ) => {
6060 const str = 123 ;
6161 const count = 3 ;
62- expect ( repeat ( str , count ) ) . toEqual ( "First argument must be a string" ) ;
62+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "First argument must be a string" ) ;
6363} ) ;
6464
6565test ( "should return error message for non-string input with invalid count" , ( ) => {
6666 const str = { text : "hello" } ;
6767 const count = - 2 ;
68- expect ( repeat ( str , count ) ) . toEqual ( "First argument must be a string" ) ;
68+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "First argument must be a string" ) ;
6969} ) ;
7070
7171test ( "should return error message for string input with non number count" , ( ) => {
7272 const str = "hello" ;
7373 const count = "3" ;
7474 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" ) ;
75+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Second argument must be a non-negative integer" ) ;
76+ expect ( ( ) => repeat ( str , count2 ) ) . toThrow ( "Second argument must be a non-negative integer" ) ;
7777} ) ;
7878
7979test ( "should return error message for string input with NaN count" , ( ) => {
8080 const str = "hello" ;
8181 const count = NaN ;
82- expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
82+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Second argument must be a non-negative integer" ) ;
8383} ) ;
8484
8585test ( "should return error message for string input with null count" , ( ) => {
8686 const str = "hello" ;
8787 const count = null ;
88- expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
88+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Second argument must be a non-negative integer" ) ;
8989} ) ;
9090
9191test ( "should return error message for string input with undefined count" , ( ) => {
9292 const str = "hello" ;
9393 const count = undefined ;
94- expect ( repeat ( str , count ) ) . toEqual ( "Second argument must be a non-negative integer" ) ;
94+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Second argument must be a non-negative integer. Received undefined " ) ;
9595} ) ;
9696
9797test ( '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" ) ;
98+ expect ( ( ) => repeat ( 'hello' ) ) . toThrow ( new Error ( "Function requires exactly two arguments: a string and a count. Received 1 arguments" ) ) ;
99+ expect ( ( ) => repeat ( "hello" , 3 , 3 ) ) . toThrow ( new Error ( "Function requires exactly two arguments: a string and a count. Received 3 arguments" ) ) ;
100100 } )
101101
0 commit comments