【问题标题】:Write unit test for NodeJs agenda job processor为 NodeJs 议程作业处理器编写单元测试
【发布时间】:2019-08-17 00:32:13
【问题描述】:

我正在使用议程框架进行作业调度链接https://github.com/agenda/agenda

调度它向用户发送电子邮件的工作,它工作正常,但我想为当前代码编写单元测试。任何帮助表示赞赏

此作业作为进程运行,例如节点作业名

module.exports = function (agenda) {

agenda.define('sendemail', function (task, done) {

 // Sending email logic here

})


// Success event when job run successfully, 
agenda.on('success:sendemail', function (task) {

// send email to admin job run successfully
})

// Fail event when job failed 
agenda.on('fail:sendemail', function (err, task) {

// send email to admin job failed

 })


// Run sendemail job
agenda.on('ready', function () {

  agenda.schedule('in 5 seconds', 'sendemail', {
    time: new Date()
  })

 agenda.start()
})

}

sendemail 有不同的状态成功,失败 用于使用 AWS SES 服务发送电子邮件。 想为上面的代码写单元测试,想验证作业是成功还是失败。

【问题讨论】:

    标签: node.js unit-testing sinon chai agenda


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2012-10-19
      • 2011-12-04
      • 2015-03-10
      • 2017-05-29
      • 2019-04-25
      • 2022-01-04
      相关资源
      最近更新 更多