Hey guys, just wanted to share my solution for using Jasmine with ImpactJS.

I'm running Xubuntu, running ImpactJS out of /var/www, and utilizing Jasmine for testing. It was a bit tricky getting access to the objects, etc. so I hope this is useful.

My folder structure is the default Impact install, but I added the "lib/jasmine-2.0.0" folder from the Jasmine .zip file to /lib. And I placed SpecRunner.html in the project root (/var/www/impact).

My SpecRunner.html contains the following:

  <!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">

  <!-- include source files here... -->
  <script type="text/javascript" src="lib/impact/impact.js"></script>
  <script type="text/javascript" src="lib/impact/system.js"></script>
  <script type="text/javascript" src="lib/impact/animation.js"></script>
  <script type="text/javascript" src="lib/impact/font.js"></script>
  <script type="text/javascript" src="lib/impact/map.js"></script>
  <script type="text/javascript" src="lib/impact/background-map.js"></script>
  <script type="text/javascript" src="lib/impact/entity.js"></script>
  <script type="text/javascript" src="lib/impact/game.js"></script>
  <script type="text/javascript" src="lib/impact/entity-pool.js"></script>

  <script type="text/javascript" src="lib/game/main.js"></script>
  <!-- 
  <script type="text/javascript" src="lib/impact/timer.js"></script>
  <script type="text/javascript" src="lib/impact/image.js"></script>
  <script type="text/javascript" src="lib/impact/loader.js"></script>
  <script type="text/javascript" src="lib/impact/input.js"></script>
  <script type="text/javascript" src="lib/impact/sound.js"></script>
  <script type="text/javascript" src="lib/impact/collision-map.js"></script>
  -->
  
  

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

  <!-- include spec files here... -->
  <script type="text/javascript" src="spec/SpecHelper.js"></script>
  <script type="text/javascript" src="spec/PlayerSpec.js"></script>



</head>

<body>
  <canvas id="canvas"></canvas>
  <script>document.getElementById("canvas").style.display = 'none';</script>
</body>
</html>


You'll notice that 1. the Jasmine files load at the end, and 2. I had to add a canvas element to the SpecRunner.html (which I hid) so that it will run in the browser window.

If you're having trouble, it might be that your JS files are loading out of order. Try rearranging them so that things that don't have dependencies load first, and make sure your Jasmine stuff loads last.

I also had to go into all the impact core js files in /lib/impact and comment out the "use static" statements - this might bite me in the butt later (I have no clue) but I couldn't access the variables until I did that. I'm open to smarter people than I telling me why I shouldn't have/didn't need to do that.

Lastly, to access game variables when actually writing tests, (Such as MyGame.font, etc.) - I referenced "MyGame.prototype.font" - that is equivalent to accessing MyGame.font for the tests. For instance, here's part of my Spec.js file:

describe("Game", function() {

  beforeEach(function() {
    ig.main( '#canvas', MyGame, 60, 320, 240, 2 );
  });

  it("should load the game object", function() {
    expect(ig.ready).toBe(true);
  });

  it("should create a canvas with height 240", function() {
    expect(ig.system.height).toBe(240);
  });

  it("should create a canvas with width 320", function() {
    expect(ig.system.width).toBe(320);
  });

  it("should load the game font", function() {
    expect(MyGame.prototype.font.path).toBe("media/04b03.font.png");
  });

  

});

Hope this helps!