【发布时间】:2019-10-17 01:01:39
【问题描述】:
我有这个功能:
function _init()
{
return _getNetDesc() // this is a promise
.then(data => {
// do something
})
.then(() => {
return _getNetOperation(); // this is a promise
})
.then( () =>{
return _getNetNodeList(); // this is a promise
})
.catch( e =>
{
logger.error("JZW","init",e);
});
}
为了测试这个函数是否抛出,我写在mocha/sinon/chai:
it("should throw eception for no GW", async () => {
_getNetDesc = sinon.stub().throws();
const test = await jzw.init;
expect(test).to.be.rejected;
});
但我明白了
TypeError: [Function: _init] is not a thenable.
【问题讨论】:
标签: node.js unit-testing promise chai sinon