UNPKG

1.38 kBJavaScriptView Raw
1'use strict';
2
3var startsWith = require('../src/startsWith'),
4 assert = require('chai').assert;
5
6describe('startsWith', function() {
7 it('returns a function if only one argument provided', function() {
8 assert.ok(startsWith('prefix') instanceof Function);
9 });
10
11 it('throws TypeError if prefix is not a string', function() {
12 assert.throws(function() {
13 startsWith({});
14 }, TypeError, /must be a string/);
15 assert.throws(function() {
16 startsWith({})({});
17 }, TypeError, /must be a string/);
18 });
19
20 it('throws Error if prefix is empty', function() {
21 assert.throws(function() {
22 startsWith('');
23 }, Error, /cannot be empty/);
24
25 assert.throws(function() {
26 startsWith('')({});
27 }, Error, /cannot be empty/);
28 });
29
30 it('checks whether string starts with given prefix', function() {
31 var prefix = 'woo';
32
33 assert.ok(startsWith(prefix, 'woohoo'));
34 assert.ok(startsWith(prefix)('woohoo'));
35 assert.ok(startsWith(prefix, 'wookieb'));
36 assert.ok(startsWith(prefix)('wookieb'));
37 assert.ok(startsWith(prefix, 'wo okieb') === false);
38 assert.ok(startsWith(prefix)('wo okieb') === false);
39 assert.ok(startsWith(prefix, '') === false);
40 assert.ok(startsWith(prefix)('') === false);
41 });
42
43});