0
我正在用摩卡書寫一個metalsmith插件及其相關測試套件。測試metalsmith插件,應該用摩卡拋出錯誤
如果缺少配置的插件應該拋出一個異常:
function plugin(config) {
...
return function(files, metalsmith, done) {
...
done(new Error("config error"));
}
}
,我嘗試用摩卡這種方式來測試它:
describe('my plugin', function() {
it('should throw an exception', function(done) {
var metalsmith = Metalsmith('test/fixtures/basic');
metalsmith
.use(myplugin({
someconfig: {
}))
.build(function(err,files) {
assert(err);
done();
});
});
});
當我運行測試我有這樣的結果:
my plugin
✓ should throw an exception
1) should throw an exception
1 passing (31ms)
1 failing
1) my plugin should throw an exception:
Error: done() called multiple times
所以它似乎測試是好的,但以某種方式運行另一次,失敗這一次...
你考慮使用'嘗試... catch'? – user949300 2016-11-27 18:52:28