Skip to content

Commit

Permalink
test(groupTask): add tests for group reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphe committed Mar 5, 2016
1 parent 67b18aa commit 283f3dd
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/plugins/groupTasks/groupSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

const groupFactory = require('../../../lib/plugins/groupTasks/group');

describe('groupFactory', () => {
it('returns a group function', () => {
expect(typeof groupFactory()).toBe('function');
});
});

describe('group reducer', () => {
it('directly returns task if its the only one', () => {
const group = groupFactory();
const task = Symbol();
const tasks = [task];

expect(group(null, task, 0, tasks)).toBe(task);
});

it('gets the task from takerInst and pushes it to collection', () => {
const fakeTakerTask = Symbol();
const fakeTakerInst = {
task: jasmine.createSpy('task').and.returnValue(fakeTakerTask),
};
const group = groupFactory(fakeTakerInst);
const displayName = 'foo';
const anotherTask = { displayName };
const tasks = [anotherTask, Symbol()];

const groupedTasks = group(null, anotherTask, 0, tasks);

expect(groupedTasks instanceof Array).toBe(true);
expect(groupedTasks[0]).toBe(fakeTakerTask);
expect(fakeTakerInst.task).toHaveBeenCalledWith(displayName);
});

it('wraps the collection for parallel call on last task', () => {
const fakeTakerTask = Symbol();
const fakeParalleled = Symbol();
const fakeTakerInst = {
task: jasmine.createSpy('task').and.returnValue(fakeTakerTask),
parallel: jasmine.createSpy('parallel').and.returnValue(fakeParalleled),
};
const group = groupFactory(fakeTakerInst);
const name = 'bar';
const anotherTask = { name };
const tasks = [Symbol(), anotherTask];
const collection = [fakeTakerTask];

expect(group(collection, anotherTask, 1, tasks)).toBe(fakeParalleled);
expect(fakeTakerInst.task).toHaveBeenCalledWith(name);
});
});

0 comments on commit 283f3dd

Please sign in to comment.