-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(groupTask): add tests for group reducer
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |