2016-02-18 21:26:18 +00:00
|
|
|
/// <reference path="../ts/typings/main.d.ts" />
|
2016-05-05 17:30:24 +00:00
|
|
|
import taskbuffer = require("../dist/index");
|
|
|
|
let should = require("should");
|
2016-05-06 00:05:45 +00:00
|
|
|
let plugins = {
|
|
|
|
q: require("q")
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup some testData to work with
|
|
|
|
let testTask:taskbuffer.Task;
|
|
|
|
let testTaskFunction = function(){
|
|
|
|
let done = plugins.q.defer();
|
|
|
|
console.log("main function executed!")
|
|
|
|
done.resolve();
|
|
|
|
return done.promise;
|
|
|
|
}
|
|
|
|
let testPreTask = new taskbuffer.Task({
|
|
|
|
taskFunction:function(){
|
|
|
|
console.log("preTask executed");
|
|
|
|
},
|
|
|
|
preTask:testTask
|
|
|
|
});
|
|
|
|
|
2016-05-04 00:49:43 +00:00
|
|
|
describe("taskbuffer",function(){
|
2016-05-06 00:05:45 +00:00
|
|
|
describe(".Task",function(){
|
|
|
|
it("new Task() should return a new task",function(){
|
|
|
|
testTask = new taskbuffer.Task({taskFunction:testTaskFunction,preTask:testPreTask});
|
2016-05-04 00:49:43 +00:00
|
|
|
});
|
2016-05-05 17:30:24 +00:00
|
|
|
it("testTask should be and instance of Task",function(){
|
|
|
|
testTask.should.be.instanceof(taskbuffer.Task);
|
2016-05-04 00:49:43 +00:00
|
|
|
});
|
|
|
|
it("testTask.idle is true",function(){
|
|
|
|
if (!testTask.idle){
|
|
|
|
throw new Error("testTask.idle is not true");
|
|
|
|
}
|
2016-05-06 00:05:45 +00:00
|
|
|
|
2016-05-04 00:49:43 +00:00
|
|
|
});
|
|
|
|
it("testTask.running is type boolean and initially false",function(){
|
|
|
|
testTask.running.should.be.type("boolean");
|
|
|
|
testTask.running.should.be.false();
|
|
|
|
});
|
2016-05-06 00:05:45 +00:00
|
|
|
it("testTask.trigger() should return Promise",function(){
|
|
|
|
testTask.trigger().should.be.Promise();
|
|
|
|
});
|
|
|
|
it("testTask.trigger() returned Promise should be fullfilled",function(done){
|
|
|
|
testTask.trigger()
|
|
|
|
.then(done);
|
|
|
|
})
|
2016-02-12 03:49:31 +00:00
|
|
|
});
|
|
|
|
});
|