收到有关尝试断言测试用例的错误消息的问题
AssertionError: expected [Function] to throw an error
at Context.it (test\index.js:24:80)
if (configVms.rts) {
describe('Real Time Services', () => {
for(let rtsConfig of configVms["rts"].rtsConfig) {
it(`Real Time Services endpoints for guid ${rtsConfig.resourceId} on ${rtsConfig.platformType} platform`, async () => {
expect(async () => await realTimeServices.main(rtsConfig)).to.throw('Host rejected');
});
}});
}
最佳答案
to.throw
仅适用于同步功能。
在您的情况下,我建议添加chai-as-promised
插件并更改测试:
if (configVms.rts) {
describe('Real Time Services', () => {
for(let rtsConfig of configVms["rts"].rtsConfig) {
it(`Real Time Services endpoints for guid ${rtsConfig.resourceId} on ${rtsConfig.platformType} platform`, async () => {
await expect(realTimeServices.main(rtsConfig)).to.be.rejectedWith('Host rejected');
});
}});
}
关于javascript - Mocha 中的异步功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57419730/