Javascript Jasmine,关闭默认报告器

Javascript Jasmine,关闭默认报告器,javascript,jasmine,Javascript,Jasmine,我有茉莉花和海关记者 var myReporter = { jasmineStarted: function(suiteInfo) { console.log('Running suite with ' + suiteInfo.totalSpecsDefined); }, suiteStarted: function(result) { console.log('Suite started: ' + result.description + ' whose fu

我有茉莉花和海关记者

var myReporter = {
  jasmineStarted: function(suiteInfo) {

    console.log('Running suite with ' + suiteInfo.totalSpecsDefined);
  },

  suiteStarted: function(result) {

    console.log('Suite started: ' + result.description + ' whose full description is: ' + result.fullName);
  },

  specStarted: function(result) {

    console.log('Spec started: ' + result.description + ' whose full description is: ' + result.fullName);
  },

  specDone: function(result) {

    console.log('Spec: ' + result.description + ' was ' + result.status);
    for(var i = 0; i < result.failedExpectations.length; i++) {


      console.log('Failure: ' + result.failedExpectations[i].message);
      console.log(result.failedExpectations[i].stack);
    }
  },

  suiteDone: function(result) {

    console.log('Suite: ' + result.description + ' was ' + result.status);
    for(var i = 0; i < result.failedExpectations.length; i++) {

      console.log('AfterAll ' + result.failedExpectations[i].message);
      console.log(result.failedExpectations[i].stack);
    }
  },
  jasmineDone: function() {
    console.log('Finished suite');
  }
};

jasmine.getEnv().addReporter(myReporter);

describe('Top Level suite', function() {
  it('spec', function() {
    expect(1).toBe(1);
  });

  describe('Nested suite', function() {
    it('nested spec', function() {
      expect(true).toBe(true);
    });
  });
});
var myReporter={
JasmineStart:函数(suiteInfo){
console.log('Running suite with'+suiteInfo.totalspecs定义);
},
suiteStarted:函数(结果){
console.log('套件已启动:'+result.description+',其完整描述为:'+result.fullName);
},
specStarted:函数(结果){
console.log('规范开始:'+result.description+',其完整描述为:'+result.fullName);
},
specDone:函数(结果){
console.log('Spec:'+result.description+'was'+result.status);
对于(变量i=0;i
现场:

现在结果显示在html和控制台上,但我需要在html中关闭它。如何仅在控制台中显示测试结果?
代码示例来自jasmine文档。

默认HTML reporter添加到文件jasmine HTML.jsboot.js

jasmine html.js
()-实际上是一个报告器本身,通过jasmine报告器API实现;
boot.js
()-一个文件,为Jasmine配置环境并执行它。此外,它还激活了默认的HTML reporter,因为这两个文件都被认为是Jasmine的核心,所以通过包含它们,您将拥有一个基本的Jasmine安装

在您的例子中,您想要实现一个定制的报告器,您想要摆脱默认的HTML报告器,所以您应该删除
jasmine HTML.js
,并用定制的报告器替换
boot.js
。Jasmine文档中有一页是关于和关于它的

Jasmine 2.x的基本自定义引导脚本(未启用任何报告器)应类似于以下内容:

(function() {

  window.jasmine = jasmineRequire.core(jasmineRequire);

  var env = jasmine.getEnv();
  var jasmineInterface = jasmineRequire.interface(jasmine, env);

  extend(window, jasmineInterface);

  window.setTimeout = window.setTimeout;
  window.setInterval = window.setInterval;
  window.clearTimeout = window.clearTimeout;
  window.clearInterval = window.clearInterval;

  var currentWindowOnload = window.onload;

  window.onload = function() {
    if (currentWindowOnload) {
      currentWindowOnload();
    }
    env.execute();
  };

  function extend(destination, source) {
    for (var property in source) destination[property] = source[property];
    return destination;
  }

}());
确保在
jasmine.js
之后包含此启动脚本

启动设置后,您可以像往常一样注册您的记者:

jasmine.getEnv().addReporter(myReporter);
或者更好——将其添加到启动脚本中


检查jsiddle:

无需删除
jasmine html.js
并摆弄自定义
boot.js
。在添加您选择的报告者之前,只需删除所有报告者:

var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().clearReporters();
jasmine.getEnv().addReporter(new jasmineReporters.TapReporter());

嗯,它仍然在我的设置中,快速搜索并没有显示任何变化,因此可能没有添加与询问者代码不同的
jasmine reporters
——我添加了一行来显示这一点,在前两行的上方lines@doyexar这回答了你的问题吗?对我来说也很有用。应标记为正确答案。