@@ -51,3 +51,38 @@ test("should throw an error when count is negative", () => {
5151 "Count must be a non-negative integer"
5252 ) ;
5353} ) ;
54+
55+ // case: Undefined String
56+ // Given that str is undefined and count is a positive integer,
57+ // When the repeat function is called with these inputs,
58+ // Then it should throw an error or return an appropriate message,
59+ // since repeating an undefined value does not make sense.
60+
61+ test ( "should throw an error when string is undefined" , ( ) => {
62+ const str = undefined ;
63+ const count = 2 ;
64+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "String must be defined" ) ;
65+ } ) ;
66+
67+ // case: Empty String
68+ // Given an empty string str and a positive integer count,
69+ // When the repeat function is called,
70+ // Then it should return an empty string, since there is nothing to repeat.
71+
72+ test ( "should return an empty string when input string is empty" , ( ) => {
73+ const str = "" ;
74+ const count = 3 ;
75+ const repeatedStr = repeat ( str , count ) ;
76+ expect ( repeatedStr ) . toEqual ( "" ) ;
77+ } ) ;
78+
79+ // case: Null String
80+ // Given that str is null and count is a positive integer,
81+ // When the repeat function is called,
82+ // Then it should throw an error, because null is not a valid string input.
83+
84+ test ( "should throw an error when string is null" , ( ) => {
85+ const str = null ;
86+ const count = 2 ;
87+ expect ( ( ) => repeat ( str , count ) ) . toThrow ( "String must be a valid string" ) ;
88+ } ) ;
0 commit comments