Verify that an exception is thrown using Mocha / Chai and async/await

后端 未结 11 889
花落未央
花落未央 2020-12-14 05:50

I\'m struggling to work out the best way to verify that a promise is rejected in a Mocha test while using async/await.

Here\'s an example that works, but I dislike t

11条回答
  •  别那么骄傲
    2020-12-14 06:47

    you can write a function to swap resolve & reject handler, and do anything normally

    const promise = new Promise((resolve, rejects) => {
        YourPromise.then(rejects, resolve);
    })
    const res = await promise;
    res.should.be.an("error");
    

提交回复
热议问题