首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mocha-phantomjs测试无输出

Mocha-phantomjs测试无输出
EN

Stack Overflow用户
提问于 2013-02-08 06:19:35
回答 2查看 3.7K关注 0票数 1

我已经成功安装了节点模块"mocha-phantomjs“here。我写了以下测试用例:

test1.js

代码语言:javascript
复制
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

代码语言:javascript
复制
<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版本,现在我得到了以下内容:

代码语言:javascript
复制
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.
EN

回答 2

Stack Overflow用户

发布于 2013-03-31 04:09:33

我通过使用到node_modules/mocha的相对路径来提供mocha.js,从而解决了这个问题。

代码语言:javascript
复制
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>

此html应位于'/test‘目录下。如果不是,请调整路径。

票数 7
EN

Stack Overflow用户

发布于 2013-06-06 11:28:40

我也有这个问题,问题是我的mocha版本--回到1.9.0修复了它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14762121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档