我试图遵循这个blog关于在ASP.NET MVC应用程序中的单独程序集中使用requirejs和jasmine。
这是我的SpecRunner.html:
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
<script type="text/javascript" src="../Beryllium.Web/Scripts/require.js"></script>
<!-- include source files here... -->
<!-- include spec files here... -->
<script type="text/javascript">
require.config({
baseUrl: '../Beryllium.Web/App/ViewModels',
paths: {
spec: '../../Beryllium.Web.UnitTests/spec'
}
})
</script>
<script type="text/javascript">
require(['spec/PlayerSpec', 'spec/SpecHelper'], function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
});
</script>
Beryllium.Web是MVC应用程序,Beryllium.Web.UnitTests是我的测试程序集。
当我加载SpecRunner文件时,我的页面上有2个错误:
GET file:///D:/code/Beryllium/Beryllium.Web/Beryllium.Web.UnitTests/spec/PlayerSpec.js require.js:1880
Uncaught Error: Script error for: spec/PlayerSpec
http://requirejs.org/docs/errors.html#scripterror
与SpecHelper.js相同的错误
我的PlayerSpec.js就是这样开始的:
define(['Player', 'Song'], function(Player, Song) {
describe("Player", function() {
var player;
var song;
beforeEach(function() {
player = new Player();
song = new Song();
});
有没有办法找出导致此错误的确切原因?当我加载SpecRunner文件时,该页面为空白,我只打开控制台才能看到此错误。
答案 0 :(得分:4)
我的愚蠢错误。在我的require config部分中,我有'../../Beryllium.Web.UnitTests'
,但目录不够,所以它正在寻找文件的错误路径。