当使用摩卡进行testing时,Node.js执行CronJob

所以,我有一些js代码,这是一个slackbot,应该简单地监听和parsing提供的date,然后启动一个CronJob按照提供的cron或date格式运行某个函数。 像这样的东西。

var CronJob = require ('cron').CronJob; ... robot.respond(date, function (msg)) { if(!isValidDate(date)) msg.reply("not a valid date); var interval = isCronDate(date) ? date : new Date(date); msg.reply("Job about to be scheduled.") var schedule = new CronJob(interval, processDataOnDate(), function() { msg.reply("hello") }, true); } 

我有一个testing这个代码的咖啡文件,我期望得到一些反馈,但是我不希望根据我在testing代码中提供的date来执行cron作业。 但是,这是。 这是正常的吗? 由于这是一个unit testing,摩卡强迫代码完成执行,还是我做错了什么? 我正在运行这个来执行我的unit testing。

 mocha --compilers coffee:coffee-script/register 

为了得到更多的信息,我把这个作为一个slackbot运行,所有这些都是以“say”和“reply”的forms完成的。 我的一个testing看起来像这样。

 beforeEach -> yield @room.user.say 'bob', '@bot schedule at 2017-05-25 18:00:00' expect(@room.messages).to.eql [ ['bob', 'bot schedule at 2017-05-25 18:00:00'] ['bot', 'Job about to be scheduled'] ] 

testing失败,并通知我,实际结果包括来自机器人的信息“hello”,尽pipe我在testing中提供的date是未来的事实。