@@ -20,13 +20,33 @@ test("should repeat the string count times", () => {
2020// Given a target string `str` and a `count` equal to 1,
2121// When the repeatStr function is called with these inputs,
2222// Then it should return the original `str` without repetition.
23+ test ( "should return the original `str` without repetition" , ( ) => {
24+ const str = "action" ;
25+ const count = 1 ;
26+ const repeatedStr = repeatStr ( str , count ) ;
27+ expect ( repeatedStr ) . toEqual ( "action" ) ;
28+ } )
2329
2430// Case: Handle count of 0:
2531// Given a target string `str` and a `count` equal to 0,
2632// When the repeatStr function is called with these inputs,
2733// Then it should return an empty string.
34+ test ( "should return an empty string when count == 0" , ( ) => {
35+ const str = "hardwork" ;
36+ const count = 0 ;
37+ const repeatedStr = repeatStr ( str , count ) ;
38+ expect ( repeatedStr ) . toEqual ( "" ) ;
39+ } )
2840
2941// Case: Handle negative count:
3042// Given a target string `str` and a negative integer `count`,
3143// When the repeatStr function is called with these inputs,
3244// Then it should throw an error, as negative counts are not valid.
45+ test ( "should throw an error" , ( ) => {
46+ const str = "responsibility" ;
47+ const count = - 5 ;
48+ // const repeatedStr = repeatStr(str, count);
49+ // In order for it to work, 'the fuction' itself should directly be passed to 'expect'.
50+ // Moreover, the function should be wrapped in a function call so jest can run it
51+ expect ( ( ) => repeatStr ( str , count ) ) . toThrow ( ) ;
52+ } )
0 commit comments