1 | 'use strict';
|
2 |
|
3 | var isArrayOf = require('../src/arrayOf'),
|
4 | assert = require('chai').assert;
|
5 |
|
6 | describe('arrayOf', function() {
|
7 | var IS_STRING = function(value) {
|
8 | return typeof value === 'string';
|
9 | };
|
10 |
|
11 | it('returns function if only one argument provided', function() {
|
12 | assert.ok(isArrayOf(IS_STRING) instanceof Function);
|
13 | });
|
14 |
|
15 | it('calls a predicate with the same context and proper arguments', function() {
|
16 | var exampleContext = {some: 'property'},
|
17 | isArrayOfString = isArrayOf(function(value, additionalArg1, additionalArg2) {
|
18 | assert.strictEqual(exampleContext, this);
|
19 | assert.ok(value === 1 || value === 2);
|
20 | assert.strictEqual(additionalArg1, 'test');
|
21 | assert.strictEqual(additionalArg2, 'value');
|
22 | });
|
23 | isArrayOfString.call(exampleContext, [1, 2], 'test', 'value');
|
24 | });
|
25 |
|
26 | it('throws a TypeError if predicate is not a function', function() {
|
27 | var notFunction = 'definitely not a function';
|
28 | assert.throws(function() {
|
29 | isArrayOf(notFunction);
|
30 | }, TypeError, /must be a function/);
|
31 | assert.throws(function() {
|
32 | isArrayOf(notFunction)([]);
|
33 | }, TypeError, /must be a function/);
|
34 | });
|
35 |
|
36 | it('returns false if value is not an array', function() {
|
37 | assert.ok(isArrayOf(IS_STRING)({}) === false);
|
38 | });
|
39 |
|
40 | it('returns true if array is empty', function() {
|
41 | assert.ok(isArrayOf(IS_STRING)([]));
|
42 | });
|
43 |
|
44 | it('checks whether every element of an array satisfies a predicate', function() {
|
45 | assert.ok(isArrayOf(IS_STRING)(['test', 'array']));
|
46 | assert.ok(isArrayOf(IS_STRING)([1, '3']) === false);
|
47 | });
|
48 | });
|