我试着测试这门课
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')
})
})测试失败:
测试完成,不运行任何断言
编辑
github上的存储库:https://github.com/epyx25/test
测试文件:https://github.com/epyx25/test/blob/master/src/test/scraper/testScraper.test.js#L12
发布于 2017-06-25 08:55:12
你得把承诺还给我。不需要断言规划:
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')
})发布于 2017-06-24 17:30:20
您必须使用断言-规划阻止测试,直到Promise通知lambda为止,例如:
test('Scraper test', t => {
t.plan(1);
return new Scraper().run().then(() => {
t.is('test', 'test')
})
})或
test.cb('Scraper test', t => {
t.plan(1);
new Scraper().run().then(() => {
t.is('test', 'test')
t.end()
})
})https://stackoverflow.com/questions/44737946
复制相似问题