我正在测试Backbone Marionette应用程序。测试页面包含以下脚本:
<script src="../testing/lib/jasmine-1.3.1/jasmine.js"></script>
<script src="../testing/lib/jasmine-1.3.1/jasmine-html.js"></script>
<script src="js/app.spec.js"></script>
奇怪的部分是,我一直收到这个错误:
Uncaught TypeError: Cannot read property 'SuiteView' of undefined
我查看了堆栈跟踪。所有测试完成后,jasmine.HtmlReporter
准备好输出测试摘要。它会调用jasmine.HtmlReporterHelpers.appendToSummary
,其中jasmine.HtmlReporter
为undefined
,如下面的屏幕截图所示。
对象方法找不到自己。这怎么可能发生?
答案 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>
<强>参考强>
Step by Step Guide for Unit Testing ExtJS Application using Jasmine
jasmine-standalone-requirejs/README.md at master · pirelenito/jasmine-standalone-requirejs
AngularJS Starter with Jasmine unit testing integrated (for usage in "http://plnkr.co/")
Integrating the Jasmine test runner for Chrome extension development
esbie/jasmine-bootstrap: A Jasmine HTML runner that uses Twitter's Bootstrap to look beautiful