我使用了jasmine 1.2.0,它运行得很好。现在我使用相同的代码一切都是一样的,唯一不同的是我转移到jasmine 2.0.1现在它不工作......所有的测试都失败了,我得到的错误是:"未捕获的TypeError:无法读取属性' env'未定义"。
以下是SpecRunner.html文件:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" href="../app/bower_components/bootstrap/dist/css/bootstrap.css"/>
<link rel="stylesheet" href="../app/bower_components/font-awsome/css/font-awesome.css"/>
<link rel="stylesheet" href="../app/bower_components/datetimepicker/jquery.datetimepicker.css"/>
<link rel="stylesheet" href="../app/css/style.css"/>
<link rel="stylesheet" href="../app/bower_components/bootstrap-multiselect/dist/css/bootstrap-multiselect.css"/>
<link rel="stylesheet" href="../app/bower_components/bootstrap-select/dist/css/bootstrap-select.css"/>
<script type="text/javascript" src="../app/bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="../app/bower_components/underscore/underscore.js"></script>
<script type="text/javascript" src="../app/bower_components/backbone/backbone.js"></script>
<script type="text/javascript" src="../app/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="../app/bower_components/moment/moment.js"></script>
<script type="text/javascript" src="../app/bower_components/handlebars/handlebars.js"></script>
<script type="text/javascript" src="../app/bower_components/datetimepicker/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="../app/bower_components/backbone-tastypie/backbone_tastypie/static/js/backbone-tastypie.js"></script>
<script type="text/javascript" src="../app/bower_components/bootstrap-multiselect/dist/js/bootstrap-multiselect.js"></script>
<script type="text/javascript" src="../app/bower_components/bootstrap-select/dist/js/bootstrap-select.js"></script>
<script type="text/javascript" src="../app/bower_components/backbone.localstorage/backbone.localStorage.js"></script>
<link rel="shortcut icon" type="image/png" href="jasmine-2.0.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="jasmine-2.0.1/jasmine.css">
<script type="text/javascript" src="jasmine-2.0.1/jasmine.js"></script>
<script type="text/javascript" src="jasmine-2.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="jasmine-2.0.1/boot.js"></script>
<script type="text/javascript" src="sinon.js"></script>
.
.
.
<!-- include spec files here... -->
.
.
.
<script type="text/javascript">
(function () {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
var oldResult = htmlReporter.reportRunnerResults;
jasmineEnv.addReporter(htmlReporter);
/* this is just for our automated tests */
window.jasmine_phantom_reporter = new jasmine.ConsoleReporter;
jasmineEnv.addReporter(jasmine_phantom_reporter);
/* */
jasmineEnv.specFilter = function (spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>
谁能告诉我有什么问题? Tnxs :) ...
答案 0 :(得分:1)
我确保您所包含的sinon.js
将支持jasmine 2.0,因为茉莉花在2.0版本中的运行方式有了重大变化。另外,请查看upgrade guide以帮助您将现有规范转换为使用2.0。
另一方面,从2.0开始,boot.js
文件应该完成您在内联脚本块中的所有工作,这样就不再需要了。
答案 1 :(得分:0)
茉莉花的第2版似乎使用boot.js
文件加载设置并启动茉莉花。您还可以在内联脚本中指定此设置。尝试删除内联脚本,并允许通过脚本包含的已包含的boot.js
加载jasmine。