当我期望抛出时,摩卡通过测试,但 muy 函数没有抛出
Mocha passing test when i expect throw, but muy function is not throwing
我有一个我希望抛出错误的函数,但如果它没有抛出它,那么 mocha 就通过了测试。
async function throwError() {
throw new Error("foo");
}
async function notThrowError() {
}
测试:
describe("bar", function(){
it("bar-2", async function() {
await expect(throwError()).throw //passes the test
})
}
describe("bar", function(){
it("bar-2", async function() {
await expect(notThrowError()).throw //passes the test, but no error has been thrown
})
}
我应该使用chai as promised
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
describe("bar", function(){
it("bar-2", async function() {
return notThrowError().should.eventually.rejected; //do not pass the test if not throw an error
})
}
我有一个我希望抛出错误的函数,但如果它没有抛出它,那么 mocha 就通过了测试。
async function throwError() {
throw new Error("foo");
}
async function notThrowError() {
}
测试:
describe("bar", function(){
it("bar-2", async function() {
await expect(throwError()).throw //passes the test
})
}
describe("bar", function(){
it("bar-2", async function() {
await expect(notThrowError()).throw //passes the test, but no error has been thrown
})
}
我应该使用chai as promised
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
describe("bar", function(){
it("bar-2", async function() {
return notThrowError().should.eventually.rejected; //do not pass the test if not throw an error
})
}