设置多长时间
正在练习用摩卡茶和噩梦进行测试。一切似乎都正常,直到我进入我的评估块。
var Nightmare = require('nightmare'),
should = require('chai').should()
describe('Frontend Masters', function() {
this.timeout(20000);
it('should show form when loaded', function(done) {
var nightmare = new Nightmare({show: true})
nightmare
.goto('https://frontendmasters.com/')
.wait('a[href*="https://frontendmasters.com/login/"]')
.click('a[href*="https://frontendmasters.com/login/"]')
.wait('#rcp_login_form')
.evaluate(function() {
return window.document.title;
}, function(result) {
result.should.equal('Login to Frontend Masters');
done();
})
.run(function(){
console.log('done')
});
});
});
我已经抛出了控制台日志,它从来没有使它进入评估。我已经尝试在几个选择器传入我的等待()函数,但它似乎没有效果。我收到的唯一错误是超时已超过。但是不管我为
你使用的是什么版本的噩梦?
.evaluate()
的签名发生了变化,我想这可能是你的问题的根源。你传递进来的第二个函数——过去是用来处理求值结果的——实际上是作为一个参数传递给第一个.evaluate()
参数。换句话说,第二个参数永远不会运行,永远不会调用done()
,并且测试将超时。
还值得一提:不直接支持.run()
。用.then()
代替。
最后,让我们修改你的源代码,以反映上述内容,让你开始:
var Nightmare = require('nightmare'),
should = require('chai')
.should()
describe('Frontend Masters', function() {
this.timeout(20000);
it('should show form when loaded', function(done) {
var nightmare = new Nightmare({
show: true
})
nightmare
.goto('https://frontendmasters.com/')
.wait('a[href*="https://frontendmasters.com/login/"]')
.click('a[href*="https://frontendmasters.com/login/"]')
.wait('#rcp_login_form')
.evaluate(function() {
return window.document.title;
})
.then(function(result) {
result.should.equal('Login to Frontend Masters');
console.log('done')
done();
})
});
});