UNPKG

1.25 kBJavaScriptView Raw
1/*!
2 * repeat-string <https://github.com/jonschlinkert/repeat-string>
3 *
4 * Copyright (c) 2014 Jon Schlinkert
5 * Licensed under the MIT License
6 */
7
8'use strict';
9
10var should = require('should');
11var repeat = require('./');
12
13describe('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});