我正在使用 Mocha 测试框架来测试Http rest-api。我想为所有测试用例生成测试报告,但是当我运行mocha --reporter html > report.html
得到以下错误

/usr/local/lib/node_modules/mocha/lib/reporters/html.js:263
  var div = document.createElement('div');
            ^
ReferenceError: document is not defined
    at fragment (/usr/local/lib/node_modules/mocha/lib/reporters/html.js:263:13)
    at new HTML (/usr/local/lib/node_modules/mocha/lib/reporters/html.js:53:14)
    at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:459:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

最佳答案

仅在浏览器中运行Mocha时才使用名为html的报告程序。从命令行运行Mocha不能使用它。

有一个名为doc的报告程序,该报告程序根据mocha --reporters输出“html文档”。顺便说一句,由于我上面给出的原因,当您运行mocha --reporters时,您不会看到html列为报告者。

09-16 15:12