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