UNPKG

1.14 kBJavaScriptView Raw
1'use strict';
2
3var isIn = require('../src/in'),
4 assert = require('chai').assert;
5
6describe('in', function() {
7 var COLLECTION = [1, '2', 'test'],
8 VALID_VALUE = 1;
9
10 it('returns function if only 1 argument provided', function() {
11 assert.ok(isIn(COLLECTION) instanceof Function);
12 });
13
14 it('throws TypeError if collection is not an array', function() {
15 assert.throws(function() {
16 isIn({});
17 }, TypeError, /must be an array/);
18
19 assert.throws(function() {
20 isIn({})(VALID_VALUE);
21 }, TypeError, /must be an array/);
22 });
23
24 it('throws Error if collection is empty', function() {
25 assert.throws(function() {
26 isIn([]);
27 }, Error, /cannot be empty/);
28
29 assert.throws(function() {
30 isIn([])(VALID_VALUE);
31 }, Error, /cannot be empty/);
32 });
33
34 it('checks whether a value exists in collection', function() {
35 assert.ok(isIn(COLLECTION, 1));
36 assert.ok(isIn(COLLECTION)(1));
37 assert.ok(isIn(COLLECTION, '1') === false);
38 assert.ok(isIn(COLLECTION)('1') === false);
39 });
40});