【发布时间】:2018-06-11 22:57:47
【问题描述】:
我在节点中有一个猫鼬模型。我想开玩笑地从我的测试套件中获取所有记录。这是我的测试:
test('should find and return all active coupon codes ', async () => {
const res = await CouponModel.find({ active: true });
expect(res).toBeDefined();
const s = res;
console.log(s);
});
如您所见,我使用了 async/await。我收到以下超时错误:
● coupon code test › should find and return all active coupon codes
Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at node_modules/jest-jasmine2/build/queue_runner.js:64:21
at ontimeout (timers.js:478:11)
at tryOnTimeout (timers.js:302:5)
at Timer.listOnTimeout (timers.js:262:5)
我在哪里做错了?我怎样才能解决这个问题?
【问题讨论】:
-
这似乎是一个奇怪的测试,你为什么要测试 mongoose.find 是否在你的代码中工作?像 .find 这样的猫鼬查询也不会返回实际的承诺 (mongoosejs.com/docs/promises.html)
标签: node.js mongodb express mongoose jestjs