Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasmine-jquery loadFixtures with Jasmine 2.0 won't work

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.

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.

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.

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...

In PlayerSpec.js:

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

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 

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 :(

like image 644
VeteranCoder Avatar asked Mar 20 '23 14:03

VeteranCoder


1 Answers

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.

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.

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.

like image 56
VeteranCoder Avatar answered Mar 23 '23 05:03

VeteranCoder