我试图编写一个Nightmare.js测试,在测试执行期间在多个点处断言/ evaluate()
。
it("should return to home page when quit button is pressed", function (done) {
var username = 'sinbad';
new Nightmare({ show: true })
.goto(url)
.type('#choosenickname', username)
.click('#write-btn')
.wait('div.game')
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
.then(function (result) {
// No 'write' buttons found
result.should.eql(0);
})
// Everything after this point doesn't work
.click('#quit-btn')
.wait('div.home')
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
.then(function (result) {
// After quitting, we should have a write button
result.should.eql(1);
done();
});
});
当我运行时,我得到了
TypeError: (intermediate value).goto(...).type(...).click(...).wait(...).evaluate(...)
.then(...).click is not a function
答案 0 :(得分:0)
根据this sample,答案似乎正在构成then()
:
it("should return to home page when quit button is pressed", function (done) {
var nightmare = loginPlayer('sinbad')
nightmare
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
.then(function (result) {
// No 'write' buttons found
result.should.eql(0);
}).then(function () {
return nightmare
.click('#quit-btn')
.wait('div.home')
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
})
.then(function (result) {
// After quitting, we should have a write button
result.should.eql(1);
done();
});
});