【发布时间】:2016-05-30 18:13:28
【问题描述】:
我正在使用 Mocha 和 Chai(BDD 模式)测试我的 Bot。
我想听事件发射器来检查我收到了哪个回复,并根据我发送的文本断言它是否有意义。
我的测试通常遵循这种模式:
beforeEach(function (done) {
bot = require('myModule').textBot;
bot.removeAllListeners('reply');
done();
});
describe('', function(){
it('', function (done) {
bot.on('reply', function (message) {
assert.include(message.text.toLowerCase(), '');
done();
});
bot.processMessage({text: 'message_that_will_trigger'});
});
});
我的测试中有多个描述和多个它。有时,错误的回复回调会触发回复(即使我重置了 beforeEach 上的所有回调),所以测试会失败。
如果我只运行特定的测试。他们通过了。
这是最好的测试方法吗?我该如何解决这个问题?
【问题讨论】:
标签: node.js mocha.js chai botframework