【发布时间】:2018-03-02 09:53:45
【问题描述】:
我有一个简单的测试应该失败,但它通过了一个错误。
我的代码:
it('my test', async () => {
const result = await resolvingPromise;
expect(result).to.equal('ok');
async function analyzeData() {
let getData = db.getData(1);
let data = await getData;
expect(data.field).to.equal(null);
}
analyzeData();
});
在这个测试中,第一个期望是可以的,但是异步函数中的期望必须失败,但是测试返回给我,但我看到了这个错误:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected Fri, 02 Mar 2018 09:47:06 GMT to equal null
(node:295) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我怎样才能以这种方式处理拒绝? 或者我需要在测试中更改我的异步功能? 那么有什么好的方法呢?
【问题讨论】:
标签: javascript node.js testing mocha.js chai