使用Jasmine 2.0的jasmine-jquery loadFixtures不起作用 [英] jasmine-jquery loadFixtures with Jasmine 2.0 won't work

查看:139
本文介绍了使用Jasmine 2.0的jasmine-jquery loadFixtures不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一天时间调试这个,我很茫然。看起来有些东西在jasmine-jquery 2.0.2中不起作用。

I've spent about a day debugging this, and I'm at a loss. It looks like something isn't working in 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。

I'm updating from Jasmine 1.3.1 and jasmine-jquery 1.5 to the newest versions. I am getting various failures depending on how I attempt to load fixtures. I get " Fixture could not be loaded: ./ExposureWorksheetFixture.html (status: parsererror, message: Invalid XML" after I tweaked jasmine-jquery to supply parameters to the ajax.fail() method.

我有另一个效果,当我调整样本茉莉花跑步者和测试时它会说零装置,零失败。当我引用jasmine-jquery,jquery 1.10.2并尝试设置时会发生这种情况如果我删除操作(但保留引用),样本就可以工作。

Another effect I have, when I tweak the sample jasmine runner and tests is it says "zero fixtures, zero failures". This happens when I reference jasmine-jquery, jquery 1.10.2, and attempt to set fixtures. If I remove the operation (but leave the references) the sample works.

我尝试加载灯具时遇到的另一个错误是(状态:错误,消息) :访问受限制的URI被拒绝)。这似乎发生在它实际上尝试加载文件时,它位于指定的位置。我看到另一个问题指向jquery需要一个真正的Web服务器来加载文件,它没有'像本地文件路径一样,但我对这些库的旧版本没有这个问题。这种情况发生在Firefox中。我得到一个 TypeError:Object不支持IE 8中的这个属性或方法。在Firefox中,我得到错误:无法加载Fixture:spec / javascripts / fixtures / fixture.html(状态:错误,消息:发生网络错误。)

Another error I get when I try to load fixtures is "(status: error, message: Access to restricted URI denied)". This seems to happen when it actually tries to load the file, which is in the assigned location. I saw another question that pointed to jquery requiring a real web server to load files, and it doesn't like local file paths, but I don't have this problem with the older versions of these libraries. This happens in Firefox. I get a TypeError: Object doesn't support this property or method in IE 8. In Firefox, I get Error: Fixture could not be loaded: spec/javascripts/fixtures/fixture.html (status: error, message: A network error occurred.).

以下是一些示例代码......

Here's some sample code...

在PlayerSpec.js中:

In PlayerSpec.js:

jasmine.getFixtures().fixturesPath = "./";
...
beforeEach(function() {
  player = new Player();
  song = new Song
loadFixtures("fixture.html");
});

在SpecRunner.html中,请注意对jquery和jasmine-jquery的额外引用:

In SpecRunner.html, note the extra references to jquery and 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>

跑步者的输出(首次测试 - 所有测试都失败)

The output on the runner (first test - all tests fail)

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:32 pm est:我只是尝试更新jasmine-jquery,以及所有内容失败了当我这样做时(Jasmine 1.31)。我想这个库肯定会发生一些事情:(

Edit 2/13/14 @ 8:32pm est: I just tried updating only jasmine-jquery, and everything fails spectacularly when I do that (Jasmine 1.31). I'm thinking there must be something going on with this library :(

推荐答案

我要感谢travisjeffery的回答。这不是我的问题的解决方案,它让我回到尝试不同的东西。我发布的具体样本的答案是我把夹具放在带有规格的文件夹中,这不是与跑步者的文件夹,并且路径是相对于跑步者定义的。然而,我的实际设置问题仍然存在。自从我最终得到一份工作样本后,我去找工作搞清楚我做错了什么。

I want to thank travisjeffery for his answer. While it wasn't the resolution to my problem, it got me back to trying different things. The answer to the specific sample I posted was that I put the fixture in the folder with the spec, which was not the folder with the runner, and the path is defined relative to the runner. However, my problem with my real setup remained. Since I finally got a working sample, I went to work figuring out what I was doing wrong.

主要问题是我的HTML Fixture虽然在jasmine-jquery 1.5中有效,但在版本2.0.2中不再有效。我以为我之前通过删除一个部分来覆盖所有语法可能性,但是当我再次 时,我发现删除我的脚本部分得到了夹具加载。我把它放回去了,但是里面的是html元素,而不是之后。我是figur这相当于XML文档中的两个根元素,因此 BAM!解析错误。

The main problem was my HTML Fixture, while valid in jasmine-jquery 1.5, was no longer valid in version 2.0.2. I thought I'd covered all the syntax possibilities earlier by removing pieces one at a time, but when I did it again, I found that removing my script section got the fixture loading. I put it back, but inside the html element, rather than after it. I figure this equated to two root elements in an XML document, thus BAM! Parse error.

另一个问题是我必须将之后的中的jasmine-jquery脚本我加载了boot.js文件,否则我得到0 fixtures 0 failure。在那之后,我不得不更新Jasmine语法,现在我再次进行了一组有效的测试。我希望这有助于其他人。

One other issue is that I have to put the jasmine-jquery script in the runner after I load the boot.js file, otherwise I get "0 fixtures 0 failures". After that, I had to update Jasmine syntax, and now I have a working set of tests again. I hope this helps others.

这篇关于使用Jasmine 2.0的jasmine-jquery loadFixtures不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆