Thursday, 25 May 2017

Node.js CronJob execution when using mocha for testing

So, I've got some js code which is supposed to simply parse the date provided and start a CronJob to run a certain function according to the cron or date format provided. Something like this.

var CronJob = require ('cron').CronJob;
...
function foo(date) {
if(!isValidDate(date)) return;
var interval = isCronDate(date) ? date : new Date(date);
var schedule = new CronJob(interval, processDataOnDate(),  true);
}

I've got a coffee file testing this code, and I expect certain responses back, but I do NOT expect the cron job to be executed based on the date I've provided in my test code. However, it is. Is this normal? Does mocha force the code to finish execution due to the fact that this is a unit test, or am I doing something wrong? I am running this to execute my unit test.

mocha --compilers coffee:coffee-script/register



via Lucas Rudd

No comments:

Post a Comment