我正在尝试使用mocha,zombie和chai进行跨页测试,遵循使用Node&表达
版本信息:macOS 10.12.2,mocha 3.5.0,chai 3.2.0,zombie 5.0.5,node v7.4.0。
QA JS代码:
var Browser = require("zombie");
var assert = require("chai").assert;
var browser;
suite("Cross-Page Tests", function () {
setup(function () {
browser = new Browser();
})
// Test (1
test("Requesting Group-Rate from the river page, should populate the referrer field", function (done) {
var referrer = "http://localhost:3000/river";
browser.visit(referrer, function () {
browser.clickLink(".requestGroupRate", function () {
assert(browser.field("referrer").value === referrer);
done();
})
})
})
// Test (2
test("Requesting Group-Rate from the coast page, should populate the referrer field", function (done) {
var referrer = "http://localhost:3000/coast";
browser.visit(referrer, function () {
browser.clickLink(".requestGroupRate", function () {
assert(browser.field("referrer").value === referrer);
done();
})
})
})
// Test (3
test("Visit request group rate page directly, should have an empty field.", function (done) {
browser.visit("http://localhost:3000/request-group-rate", function () {
assert(browser.field("referrer").value === "");
done();
})
})
})
在终端中显示的内容(在mocha -u tdd -R spec qa/tests-crosspage.js 2>/dev/null
之后):
...
1) Cross-Page Tests Requesting Group-Rate from the river page, should populate the referrer field:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
2) Cross-Page Tests Requesting Group-Rate from the coast page, should populate the referrer field:
Uncaught AssertionError: No link matching '.requestGroupRate'
at Browser.clickLink (node_modules/zombie/lib/index.js:695:7)
at qa/tests-crosspage.js:28:21
at Browser.done (node_modules/zombie/lib/eventloop.js:589:11)
at node_modules/zombie/lib/document.js:819:13
at process._tickCallback (internal/process/next_tick.js:103:7)
3) Cross-Page Tests Visit request group rate page directly, should have an empty field.:
Uncaught AssertionError: No link matching '.requestGroupRate'
at Browser.clickLink (node_modules/zombie/lib/index.js:695:7)
at qa/tests-crosspage.js:18:21
at EventLoop.done (node_modules/zombie/lib/eventloop.js:589:11)
at Immediate.<anonymous> (node_modules/zombie/lib/eventloop.js:688:71)
让我困惑的是什么:
1)我在每次测试中都调用done()
,但为什么测试1仍然超时?
2)在测试3中,没有与链接匹配'.requestGroupRate'相关的代码,那么它来自哪里?
注意:
我手动检查了localhost:3000\river
页面。有一个<a>
类,requestGroupRate
。
海岸页面不存在,因此测试2是必须失败的测试。
答案 0 :(得分:0)
https://github.com/EthanRBrown/web-development-with-node-and-express/issues/58
测试必须从
改变assert(browser.field('referrer').value === 'referrer');
到
assert(browser.field('referrer').value === ' ');