Jasmine HtmlReporter自称,发现自己未定义

时间:2013-09-19 18:14:07

标签: javascript jasmine

我正在测试Backbone Marionette应用程序。测试页面包含以下脚本:

  • Jasmine:<script src="../testing/lib/jasmine-1.3.1/jasmine.js"></script>
  • Jasmine HTML记者:<script src="../testing/lib/jasmine-1.3.1/jasmine-html.js"></script>
  • 我的规范:<script src="js/app.spec.js"></script>
  • 设置:window.onload代码已复制exactly from the Jasmine github page

奇怪的部分是,我一直收到这个错误:

Uncaught TypeError: Cannot read property 'SuiteView' of undefined 

我查看了堆栈跟踪。所有测试完成后,jasmine.HtmlReporter准备好输出测试摘要。它会调用jasmine.HtmlReporterHelpers.appendToSummary,其中jasmine.HtmlReporterundefined,如下面的屏幕截图所示。

对象方法找不到自己。这怎么可能发生?

1 个答案:

答案 0 :(得分:0)

  

未捕获的TypeError:无法读取未定义的属性'SuiteView'

SuiteView是当前正在执行的套件的属性,在这种情况下缺失。 Jasmine具有以下生命周期:

var jasmineEnv = jasmine.getEnv (); //Initialize Environment
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter (); //Initialize Reporter
jasmineEnv.addReporter (htmlReporter); //Add Reporter
jasmineEnv.execute (); //Start Suite

这是一个完整的脚本:

<script>
function load()
  {
  var description = location.hash.match(/".+"/).toString().replace(/"/g,"");
  var spec = location.hash.match(/function.+}/).toString();
  var result = Function("return " + spec)();
  var len = jasmine.getEnv().topSuite().children.length;
  var test;
  var suite;
  var suite_name;
  var reporter_args;
  var reporter_methods;
  var i;

  test = jasmine.getEnv().it(description, result);
  suite = jasmine.getEnv().topSuite().children[len];
  reporter_args = jasmine.HtmlReporter.toString().match(/options\.[a-zA-Z]+/g);
  reporter_methods = jasmine.HtmlReporter.toString().match(/this\.[a-zA-Z]+/g)
  var suite_name = suite.fullname;
  for(i = 0; i < len; i++)
    {
    jasmine.getEnv().topSuite().children.shift();
    }
  jasmine.getEnv().execute(suite_name);
  }
</script>

<强>参考