【发布时间】:2020-08-25 23:52:51
【问题描述】:
尝试学习玩笑,使用下面的代码测试不会终止。 db.close promise 的状态仍然是pending。
我在执行测试时收到以下消息。你能帮我解决这个问题吗?谢谢。
Jest 在测试运行完成后一秒没有退出。
这通常意味着在您的测试中存在未停止的异步操作。考虑使用 --detectOpenHandles 运行 Jest 来解决此问题。
test('Should be ', async () => {
/*DO NOT call the next four function directly, check if a merchant/terminal exists before starting
a transaction and insert document if required.*/
//functions.insertTerminalRecordInMongo();
//functions.insertTerminalRecordInMongo();
var record = await functions.getMongoField('terminal', {'attributes.TID': 'T55001001'});
//functions.deleteTerminalRecordInMongo('terminal',{'attributes.TID' :'T55001001'})
DE22Test.buildTransactionAndSend({MTI: "1104", dataElements: {DE22: "XYZ"}})
expect(functions.getAsRequestField('DE22')).toBe("XYZ")
expect(functions.getAsResponseField('DE39')).toBe("00")
expect(functions.getAsResponseField('DE01')).toBe("00")
})
从 mongodb 中检索文档的函数。
//Return a mongo record based on collectionName and FieldName
getMongoField: (collectionName, queryElement) => {
console.info("Querying Mongo");
mongoClient.connect(uri, function (err, db) {
if (err) throw err;
dbo = db.db("axis")
dbo.collection(collectionName).find({}, queryElement).toArray(function (err, result) {
if (err) throw err;
console.info('Queried document', result[0]);
});
db.close()
})
},
【问题讨论】:
标签: javascript mongodb jestjs