mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
Merge pull request #523 from MaoShizhong/repeat-string-builtin
02_repeatString: Add test preventing use of `String.prototype.repeat`
This commit is contained in:
@@ -13,6 +13,13 @@ describe('repeatString', () => {
|
||||
test.skip('repeats the string 0 times', () => {
|
||||
expect(repeatString('bye', 0)).toEqual('');
|
||||
});
|
||||
test.skip('does not use the built-in String repeat method', () => {
|
||||
/* Even though there is a built-in String repeat method,
|
||||
in this exercise specifically, we want you to practise using loops */
|
||||
jest.spyOn(String.prototype, 'repeat').mockName('Built-in String repeat method');
|
||||
repeatString("don't use the built-in repeat method!", 1);
|
||||
expect(String.prototype.repeat).not.toHaveBeenCalled();
|
||||
});
|
||||
test.skip('returns ERROR with negative numbers', () => {
|
||||
expect(repeatString('goodbye', -1)).toEqual('ERROR');
|
||||
});
|
||||
|
||||
@@ -13,6 +13,13 @@ describe('repeatString', () => {
|
||||
test('repeats the string 0 times', () => {
|
||||
expect(repeatString('bye', 0)).toEqual('');
|
||||
});
|
||||
test('does not use the built-in String repeat method', () => {
|
||||
/* Even though there is a built-in String repeat method,
|
||||
in this exercise specifically, we want you to practise using loops */
|
||||
jest.spyOn(String.prototype, 'repeat').mockName('Built-in String repeat method');
|
||||
repeatString("don't use the built-in repeat method!", 1);
|
||||
expect(String.prototype.repeat).not.toHaveBeenCalled();
|
||||
});
|
||||
test('returns ERROR with negative numbers', () => {
|
||||
expect(repeatString('goodbye', -1)).toEqual('ERROR');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user