8000 Merge pull request #523 from MaoShizhong/repeat-string-builtin · rokuruby/javascript-exercises@ace1d6e · GitHub
[go: up one dir, main page]

Skip to content

Commit ace1d6e

Browse files
authored
Merge pull request TheOdinProject#523 from MaoShizhong/repeat-string-builtin
02_repeatString: Add test preventing use of `String.prototype.repeat`
2 parents fd555e3 + 5ea6746 commit ace1d6e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

02_repeatString/repeatString.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ describe('repeatString', () => {
1313
test.skip('repeats the string 0 times', () => {
1414
expect(repeatString('bye', 0)).toEqual('');
1515
});
16+
test.skip('does not use the built-in String repeat method', () => {
17+
/* Even though there is a built-in String repeat method,
18+
in this exercise specifically, we want you to practise using loops */
19+
jest.spyOn(String.prototype, 'repeat').mockName('Built-in String repeat method');
20+
repeatString("don't use the built-in repeat method!", 1);
21+
expect(String.prototype.repeat).not.toHaveBeenCalled();
22+
});
1623
test.skip('returns ERROR with negative numbers', () => {
1724
expect(repeatString('goodbye', -1)).toEqual('ERROR');
1825
});

02_repeatString/solution/repeatString-solution.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ describe('repeatString', () => {
1313
test('repeats the string 0 times', () => {
1414
expect(repeatString('bye', 0)).toEqual('');
1515
});
16+
test('does not use the built-in String repeat method', () => {
17+
/* Even though there is a built-in String repeat method,
18+
in this exercise specifically, we want you to practise using loops */
19+
jest.spyOn(String.prototype, 'repeat').mockName('Built-in String repeat method');
20+
repeatString("don't use the built-in repeat method!", 1);
21+
expect(String.prototype.repeat).not.toHaveBeenCalled();
22+
});
1623
test('returns ERROR with negative numbers', () => {
1724
expect(repeatString('goodbye', -1)).toEqual('ERROR');
1825
});

0 commit comments

Comments
 (0)
0