У меня есть простой асинхронный тест мокки, но обратный вызов done()
никогда не вызывает вызова.Как выполнить проверку async/await с помощью TypeScript и mocha
describe("RiBot", function() {
it("should start with a random topic", async (done) => {
await RiBot.init();
let topic = RiBot.getTopic("testuser")
assert.equal(topic, "FAILHERE");
done()
})
})
В этом случае утверждение должно завершиться неудачно, но вместо этого я просто получаю таймаут.
RiBot
RibotTest topic +0ms undefined
1) should start with a random topic
0 passing (2s)
1 failing
1) RiBot should start with a random topic:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
редактировать: когда я запускаю только в качестве стандартного кода JS с утверждают:
async function testRiBot() {
try {
await RiBot.init()
let topic = RiBot.getTopic("testuser")
debug('topic', topic)
assert.equal(topic, "FAILHERE", 'fail match on topic');
} catch(err) {
debug("err", err, err.stack)
}
}
я получаю исключение выброшенное как ошибки.
RibotTest err +2ms { [AssertionError: fail match on topic]
name: 'AssertionError',
actual: 'undefined',
expected: 'FAILHERE',
operator: '==',
message: 'fail match on topic',
generatedMessage: false } AssertionError: fail match on topic
at /Users/dc/dev/rikai/boteditor/test/RiBot_test.js:19:20
at next (native)
at fulfilled (/Users/dc/dev/rikai/boteditor/test/RiBot_test.js:4:58)
at process._tickCallback (node.js:412:9)
Может ли кто-нибудь предоставить простой пример с помощью машинописного текста async/wait и mocha?
Вы когда-нибудь видели это @dcsan? – timothyclifford