8000 Add test preventing use of built-in String repeat method · 10h30/odin-javascript-exercises@5ea6746 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ea6746

Browse files
committed
Add test preventing use of built-in String repeat method
1 parent fd555e3 commit 5ea6746

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