我有一个文件,
function fetchDevices () {
device.findAll()
.then(allDevices =>
console.log("Fetched for DB")
)
}
在测试文件中我模拟了设备
。现在我想知道/等待此 findAll()
返回一个 promise ,然后在测试函数中继续断言。我已经尝试了很多东西,但 setTimeout
并不是我想要的。
我不能 stub devices
因为我已经用另一个库模拟它,这省去了模拟或 stub 属性的很多麻烦。
非常感谢您的帮助。
最佳答案
改变:
function fetchDevices () {
device.findAll()
.then(allDevices =>
console.log("Fetched for DB")
)
}
到:
function fetchDevices () {
return device.findAll()
.then(allDevices =>
console.log("Fetched for DB")
)
}
现在 fetchDevices
返回一个 promise ,您可以然后
它。
关于javascript - 诗乃与 Mocha : How to await for a promised to be resolved before assertion in test function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57009072/