【问题标题】:Mocha-phantomjs testing no outputMocha-phantomjs 测试没有输出
【发布时间】: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


【解决方案1】:

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

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

这个 html 应该在 '/test' 目录下。如果不是,请调整路径。

【讨论】:

  • 我已经给出了相对路径,但它仍然显示相同的错误。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多