简体   繁体   English

摩卡中的异步功能

[英]async function in mocha

Receiving issues on trying to assert an error message for the test case 收到有关尝试断言测试用例的错误消息的问题

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 is applicable only to synchronous functions. to.throw仅适用于同步功能。 In your case I would recommend to add chai-as-promised plugin and change test: 在您的情况下,我建议添加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');
        });
    }});
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM