-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
34 lines (27 loc) · 1.05 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var assert = require('assert');
var toArray = require('./');
describe('toArray()', function(){
var args = function () {
return arguments;
};
function Collection(array) {
this.length = array.length;
this.toArray = function () { return array; }
}
var collection = new Collection([1, 2]);
var cases = [
{ name: 'null', param: null, result: [] },
{ name: 'undefined', param: void 0, result: [] },
{ name: 'arrays', param: [1, 2, 3], result: [1, 2, 3] },
{ name: 'numbers', param: 42, result: [42] },
{ name: 'strings', param: 'id', result: ['id'] },
{ name: 'delimited strings', param: 'a,b,c', delimiter: ',', result: ['a','b','c'] },
{ name: 'arguments', param: args(1, 2), result: [1, 2] },
{ name: 'collections', param: collection, result: [1, 2] }
];
cases.forEach(function (test) {
it(test.name, function() {
assert.deepEqual(toArray(test.param, test.delimiter), test.result);
});
});
});