【发布时间】:2018-04-17 02:43:22
【问题描述】:
我尝试使用 'mocha' 和 'chai' 进行单元测试,但我的测试结果有问题,它总是通过。 请看一下。
UnitTest.spec.ts
import PostgresService from "../src/Services/PostgresService"
import {expect} from "chai"
import 'mocha'
describe('Postgres Override Test function', () => {
it('should return any number but not zero', async () => {
let client = new PostgresService();
let result = await client.getLatestCMD("Servo");
try{
console.log("Type : " + typeof(result));
console.log("Value : " + result.rows[0].id);
expect(result.rows[0].id).to.equal(0)
}catch(error){
}
})
})
【问题讨论】:
-
移除 try catch 块
-
@LiroyLeshed.com 成功了!但为什么呢?
-
许多单元测试框架通过抛出异常来指示错误。如果您静默地捕获异常,您实际上已经禁用了信号机制。
标签: unit-testing typescript mocha.js bdd chai