1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var should = require('should');
|
11 | var repeat = require('./');
|
12 |
|
13 | describe('repeat', function () {
|
14 | it('should return an empty string when a number is not given:', function () {
|
15 | repeat('a').should.equal('');
|
16 | });
|
17 |
|
18 | it('should return an empty string when zero is given as the number:', function () {
|
19 | repeat('', 0).should.equal('');
|
20 | repeat('a', 0).should.equal('');
|
21 | });
|
22 |
|
23 | it('should return an empty string when null is given as the number:', function () {
|
24 | repeat('', null).should.equal('');
|
25 | repeat('a', null).should.equal('');
|
26 | });
|
27 |
|
28 | it('should throw an error when no string is given:', function () {
|
29 | (function() {repeat(10); }).should.throw('repeat-string expects a string.');
|
30 | (function() {repeat(null); }).should.throw('repeat-string expects a string.');
|
31 | });
|
32 |
|
33 | it('should repeat the given string n times', function () {
|
34 | repeat('a', 0).should.equal('');
|
35 | repeat('a', 1).should.equal('a');
|
36 | repeat('a', 2).should.equal('aa');
|
37 | repeat('a', 10).should.equal('aaaaaaaaaa');
|
38 | repeat('a ', 10).trim().should.equal('a a a a a a a a a a');
|
39 | });
|
40 | });
|