【发布时间】:2020-11-30 23:35:55
【问题描述】:
我已经移动了很多,并尝试使用done()、async 和链接then(),移动describe(),我最近的尝试是按照Async function in mocha before() is alway finished before it() spec? 的建议在之前返回一个承诺。
表示表已创建的console.log('finished!') 打印在表示测试开始的console.log('starting tests') 之后。
我应该提到,以某种方式创建了用户表,并且所有用户测试都像魅力一样工作。
我所有的测试都失败了,因为它们试图对不存在的表执行操作。我不确定了。如何确保before在实际测试之前运行?
describe('', async () => {
before('setting up database', async () => {
return new Promise(async resolve => {
await db.users.createTable()
await db.stores.createTable()
await db.booths.createTable()
await db.reservations.createTable()
await db.clothing.createTable()
console.log('finished!')
resolve()
})
})
describe('running datalayer test suite', async () => {
try {
console.log('starting tests')
await userTest()
await storeTest()
await boothTest()
await reservationTest()
await clothingTest()
} catch (e) {
console.warn(e)
}
})
after('destroying db', async () => {
await db.clothing.dropTable()
await db.reservations.dropTable()
await db.booths.dropTable()
await db.stores.dropTable()
await db.users.dropTable()
})
})
starting tests
(node:16339) UnhandledPromiseRejectionWarning: Error: something went wrong with persisting the store: error: relation "stores" does not exist
at module.exports (/home/jonas/Projects/sellsome-backend/exceptions/query-exception.js:2:19)
at Object.insert (/home/jonas/Projects/sellsome-backend/logiclayer/stores.js:23:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:16339) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:16339) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
..... tons more
finished!
编辑:摩卡版本 8.1.1
【问题讨论】:
标签: javascript node.js testing mocha.js