我花了大约一天的时间来调试这个,我很茫然。jasmine-jquery 2.0.2 中似乎有些东西不起作用。
我正在从 Jasmine 1.3.1 和 jasmine-jquery 1.5 更新到最新版本。根据我尝试加载固定装置的方式,我遇到了各种失败。在我调整 jasmine-jquery 以向 ajax.fail() 方法提供参数后,我得到“无法加载 Fixture: ./ExposureWorksheetFixture.html (status: parsererror, message: Invalid XML”。
我的另一个效果是,当我调整示例 jasmine runner 并进行测试时,它会显示“零固定装置,零故障”。当我引用 jasmine-jquery、jquery 1.10.2 并尝试设置固定装置时,就会发生这种情况。如果我删除该操作(但留下参考),则该示例有效。
我尝试加载固定装置时遇到的另一个错误是“(状态:错误,消息:访问受限 URI 被拒绝)”。这似乎发生在它实际尝试加载位于指定位置的文件时。我看到另一个问题指出 jquery 需要一个真正的 Web 服务器来加载文件,并且它不喜欢本地文件路径,但我对这些库的旧版本没有这个问题。这发生在 Firefox 中。我TypeError: Object doesn't support this property or method
在 IE 8 中得到一个。在 Firefox 中,我得到Error: Fixture could not be loaded: spec/javascripts/fixtures/fixture.html (status: error, message: A network error occurred.)
.
这是一些示例代码...
在 PlayerSpec.js 中:
jasmine.getFixtures().fixturesPath = "./";
...
beforeEach(function() {
player = new Player();
song = new Song
loadFixtures("fixture.html");
});
在 SpecRunner.html 中,注意对 jquery 和 jasmine-jquery 的额外引用:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jasmine Spec Runner v2.0.0</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>
<script type="text/javascript" src="lib/jquery-1.10.2.js"></script>
<script type="text/javascript" src="lib/jasmine-jquery.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="src/Player.js"></script>
<script type="text/javascript" src="src/Song.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
</head>
<body>
</body>
</html>
跑步者的输出(第一次测试 - 所有测试都失败)
Jasmine2.0.0finished in 0.019s
raise exceptions5 specs, 5 failuresSpec List | Failures
Player should be able to play a Song
Error: Fixture could not be loaded: spec/javascripts/fixtures/fixture.html (status: error, message: Access to restricted URI denied) in file:///D:/Temp/jas/lib/jasmine-jquery.js (line 132)
jasmine.Fixtures.prototype.loadFixtureIntoCache_/request<@file:///D:/Temp/jas/lib/jasmine-jquery.js:132 jQuery.Callbacks/fire@file:///D:/Temp/jas/lib/jquery-1.10.2.js:3048 jQuery.Callbacks/self.add@file:///D:/Temp/jas/lib/jquery-1.10.2.js:3094 jasmine.Fixtures.prototype.loadFixtureIntoCache_@file:///D:/Temp/jas/lib/jasmine-jquery.js:131 jasmine.Fixtures.prototype.getFixtureHtml_@file:///D:/Temp/jas/lib/jasmine-jquery.js:115 jasmine.Fixtures.prototype.read@file:///D:/Temp/jas/lib/jasmine-jquery.js:77 jasmine.Fixtures.prototype.load@file:///D:/Temp/jas/lib/jasmine-jquery.js:65 jasmine.Fixtures.prototype.proxyCallTo_@file:///D:/Temp/jas/lib/jasmine-jquery.js:161 window.loadFixtures@file:///D:/Temp/jas/lib/jasmine-jquery.js:763 @file:///D:/Temp/jas/spec/PlayerSpec.js:9 attemptSync@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1510 QueueRunner.prototype.run@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1498 QueueRunner.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1485 Env/queueRunnerFactory@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:518 Spec.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:309 Suite.prototype.execute/wrapChildAsAsync/<@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1708 attemptAsync@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1520 QueueRunner.prototype.run@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1496 QueueRunner.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1485 Env/queueRunnerFactory@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:518 Suite.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1696 Suite.prototype.execute/wrapChildAsAsync/<@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1708 attemptAsync@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1520 QueueRunner.prototype.run@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1496 QueueRunner.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1485 Env/queueRunnerFactory@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:518 Suite.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1696 @file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:541 attemptAsync@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1520 QueueRunner.prototype.run@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1496 QueueRunner.prototype.execute@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:1485 Env/queueRunnerFactory@file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:518 @file:///D:/Temp/jas/lib/jasmine-2.0.0/jasmine.js:548 window.onload@file:///D:/Temp/jas/lib/jasmine-2.0.0/boot.js:170
编辑 2/13/14 @ 8:32pm EST:我刚刚尝试只更新 jasmine-jquery,当我这样做时一切都失败了(Jasmine 1.31)。我在想这个库一定有什么问题:(