Milad
Milad

Reputation: 37

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');
        });
    }});
}

Upvotes: 0

Views: 37

Answers (1)

Alex
Alex

Reputation: 1839

to.throw is applicable only to synchronous functions. In your case I would recommend to add chai-as-promised plugin and change test:

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');
        });
    }});
}

Upvotes: 2

Related Questions