gpt4 book ai didi

node.js - 使用 ava 测试 promise

转载 作者:行者123 更新时间:2023-11-28 20:19:58 24 4
gpt4 key购买 nike

我尝试测试这个类

class Scraper {
async run() {
return await nightmare
.goto(this.url)
.wait('...')
.evaluate(()=>{...})
.end
}
}

我的测试是这样的:

test('Scraper test', t => {
new Scraper().run().then(() => {
t.is('test', 'test')
})
})

测试失败:

Test finished without running any assertions

编辑

github 上的仓库:https://github.com/epyx25/test

测试文件:https://github.com/epyx25/test/blob/master/src/test/scraper/testScraper.test.js#L12

最佳答案

您需要返回 promise 。不需要断言计划:

test('Scraper test', t => {
return new Scraper().run().then(() => {
t.is('test', 'test')
})
})

或者更好的是,使用异步测试:

test('Scraper test', async t => {
await new Scraper().run()
t.is('test', 'test')
})

关于node.js - 使用 ava 测试 promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44737946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com