Mocha-phantomjstesting没有输出

我已经在这里成功安装了节点模块“mocha-phantomjs”。 我写了下面的testing用例:

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和jstesting,并将其与Jenkins集成,我认为这个使用TAP报告是没问题的。 欢迎任何其他build议。

编辑

我更新了我的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. 

我通过使用相对于node_modules / mocha的path来提供mocha.js来解决这个问题。

 <div id="mocha"></div> <script src="../node_modules/mocha/mocha.js"></script> <script src="../node_modules/chai/chai.js"></script> 

这个html应该在'/ test'目录下。 如果没有,请调整path。

我也有这个问题,问题是我的摩卡版本 – 回到1.9.0修复它。