摩卡
supports Promises out-of-the-box
; 你只需要
return
it()
. 如果它解决了,那么测试就通过了,否则它就失败了。
async
functions always implicitly return a
Promise
async function getFoo() {
return 'foo'
}
describe('#getFoo', () => {
it('resolves with foo', () => {
return getFoo().then(result => {
assert.equal(result, 'foo')
})
})
})
你不需要
done
异步
为了你的
it
.
async/await
:
async function getFoo() {
return 'foo'
}
describe('#getFoo', () => {
it('returns foo', async () => {
const result = await getFoo()
assert.equal(result, 'foo')
})
})
无论哪种情况,
不要
声明
如果您使用上述任何方法,则需要删除
完成
完全脱离你的代码。经过
完成
作为一个论据
提示摩卡,你打算最终调用它。
这个
完成