【发布时间】:2016-09-24 15:42:36
【问题描述】:
我想将Mocha 与ES6 generators 一起使用,并可选择与expect 一起使用。经过一番研究,我构建了以下代码sn-p:
describe('test', function() {
it('should not work', function() {
expect(function() {
return co(function*() {
yield Service.validate();
});
}).to.throw(new Error('error'));
});
});
Service.validate 抛出 new Error('error'),这就是我的 expect。
module.exports = {
validate: function() {
return co(function*() {
// use yield to access db and so on
throw new Error('error');
});
}
};
但是,以下代码会抛出 AssertionError: expected [Function] to throw 'Error: error'。有人可以帮忙吗?
【问题讨论】:
-
如果
Service.validate()是基于promise 的并且只在co包装器中使用,那么问题涉及promise,而不是生成器。 -
更新了标题...
标签: javascript node.js ecmascript-6 mocha.js chai