【发布时间】:2013-06-07 00:52:37
【问题描述】:
我已经成功安装了节点模块“mocha-phantomjs”here。我写了以下测试用例:
test1.js
describe("DOM Tests", function () {
var el = document.createElement("div");
el.id = "myDiv";
el.innerHTML = "Hi there!";
el.style.background = "#ccc";
document.body.appendChild(el);
var myEl = document.getElementById('myDiv');
it("is in the DOM", function () {
expect(myEl).to.equal(null);
});
it("is a child of the body", function () {
expect(myEl.parentElement).to.equal(document.body);
});
it("has the right text", function () {
expect(myEl.innerHTML).to.equal("Hi there!");
});
it("has the right background", function () {
expect(myEl.style.background).to.equal("rgb(204, 204, 204)");
});
});
TestCase.html
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="mocha.js"></script>
<script src="chai.js"></script>
<script>
mocha.ui('bdd');
mocha.reporter('html');
expect = chai.expect;
</script>
<script src="test1.js"></script>
<script>
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
else { mocha.run(); }
</script>
</body>
</html>
我得到的是绝对没有输出,即使我在我的 js 文件中打错了字。
这里的要点是我必须在无头服务器中使用一些自动化的 dom 和 js 测试并将其与 Jenkins 集成,我认为使用 TAP 报告是可以的。欢迎任何其他建议。
编辑
我更新了我的 phantomjs 版本,现在我得到以下信息:
TypeError: 'undefined' is not a function (evaluating 'mocha.ui('bdd')')
file:///home/seventeenlive/site/tests/TestRunner2.html:11
ReferenceError: Can't find variable: describe
file:///home/seventeenlive/site/tests/test1.js:20
ReferenceError: Can't find variable: process
mocha-phantomjs/core_extensions.js:21
mocha-phantomjs/core_extensions.js:82
ReferenceError: Can't find variable: process
phantomjs://webpage.evaluate():2
phantomjs://webpage.evaluate():8
phantomjs://webpage.evaluate():8
ReferenceError: Can't find variable: process
phantomjs://webpage.evaluate():3
phantomjs://webpage.evaluate():17
phantomjs://webpage.evaluate():17
Failed to start mocha.
【问题讨论】:
-
你能把你的文件夹结构贴在这里吗?
-
节点不为我服务 mocha.js 和 chai.js 吗?
-
我认为你需要安装 Mocha 并将 test 默认放在 test 文件夹下。也许这有帮助。
-
你运行的是什么版本的phantomjs?我在使用旧版本的 phantomjs 时遇到问题,请尝试更新到最新版本。
标签: node.js phantomjs mocha.js