【发布时间】:2019-04-23 04:10:52
【问题描述】:
我开始使用 Jest 测试我的代码,但我无法通过看似简单的测试。我只是想检查我从 Maogoose 数据库请求中收到的内容是否是一个对象。
fetchPosts() 函数正在工作,因为我将它与 React 前端连接起来,它可以正确显示数据。
这是我的函数fetchPosts():
module.exports = {
fetchPosts() {
return new Promise((resolve, reject) => {
Posts.find({}).then(posts => {
if (posts) {
resolve(posts)
} else {
reject()
}
})
})
}
}
我的测试:
it('should get a list of posts', function() {
return posts.fetchPosts().then(result => {
expect(typeof result).toBe('object')
})
})
这使得测试失败,Jest 说
'超时 - 在 jest.setTimeout 指定的 5000 毫秒超时内未调用异步回调。'
问题:我怎样才能使这个测试通过?
【问题讨论】:
标签: javascript node.js reactjs jestjs