Skip to content

Commit

Permalink
util.gather test
Browse files Browse the repository at this point in the history
  • Loading branch information
lxjwlt committed Feb 15, 2017
1 parent db33983 commit f1600d9
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion tests/src/util/gather.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const gather = require('../../../src/util/gather');

describe('util/gather.js', () => {


it('next item in array', () => {
let arr = [1, 2, 3];
let list = gather(arr);
Expand Down Expand Up @@ -46,5 +45,72 @@ describe('util/gather.js', () => {

});

it('iterator arr', () => {
let arr = [1, 2, 3];
let list = gather(arr);
let result = [];

for (let value of list) {
assert.include(arr, value);
result.push(value);
}

assert.notStrictEqual(result[0], result[1]);
assert.notStrictEqual(result[1], result[2]);
assert.notStrictEqual(result[0], result[2]);

});

it('next item in object', () => {
let obj = {
item1: 1,
item2: 2,
item3: 3
};
let list = gather(obj);
let result = [];

for (let item of list) {
assert.deepEqual(Object.assign({}, obj, item), obj);
result.push(item);
}

assert.notDeepEqual(result[0], result[1]);
assert.notDeepEqual(result[1], result[2]);
assert.notDeepEqual(result[0], result[2]);

});

it('empty array', () => {
let list = gather([]);

assert.strictEqual(list.next(), undefined);
assert.strictEqual(list.next(), undefined);

});

it('empty obj', () => {
let list = gather({});

assert.strictEqual(list.next(), undefined);
assert.strictEqual(list.next(), undefined);

});

it('no iterator in empty array', () => {

for (let value of gather([])) {
assert.strictEqual(1, 2);
}

});

it('no iterator in empty obj', () => {

for (let value of gather({})) {
assert.strictEqual(1, 2);
}

});

});

0 comments on commit f1600d9

Please sign in to comment.