3

I'm trying to run my usual jasmine-node tests with ember.js and because ember requires handlebars to be loaded I included that library also.

Yet for some reason when ember hits this code

window.Handlebars

I get undefined.

Here is how i'm loading jquery/handlebars/ember in my jasmine tests

var jsdom = require("jsdom");
window = jsdom.jsdom("<html></html");
global.window = window;

require("path/to/jquery");
require("path/to/handlebars-1.0.0.beta.6");
require("path/to/ember-1.0.pre");

describe("test demo", function() {
  it("should not blow up when running this", function() {
    expect(2).toBe(2);
  });
});

I could easily hack this into the bottom of the handlebars.js file but I'd like to understand what else could be done to avoid having to modify this library directly for tests.

window.Handlebars = Handlebars;

(followed by this line before I load ember in the helper)

global.Handlebars = window.Handlebars;

** update **

I also have the same problem with ember-data.js

It seems that setting window.Foo is not enought -instead I actually need to set global.Foo (any ideas on a work around for this?)

(function() {
window.DS = Ember.Namespace.create({
  CURRENT_API_REVISION: 4
});
})();
global.DS = window.DS; //I had to add this to make DS available
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
  • I decided to roll my own javascript test runner using node / phantomJS / jasmine that allows you to run tests even when larger projects like Ember/Handlebars are part of your dependencies without the need to use a browser (so the best parts of jasmine-node but less pain when you need to get ember.js code under test). https://npmjs.org/package/jasmine-phantom-node – Toran Billups Oct 10 '12 at 23:34
  • Hey toran... any update to this? if so, could you answer your own question, please? – Julian Leviston Apr 27 '14 at 05:54
  • Honestly I haven't use jasmine in over a year as QUnit is a better match these days (seems to get features first anyway). I'd like to update it but beyond writing my own test runner ... this doesn't have a happy ending. – Toran Billups Apr 27 '14 at 19:05
  • I'm just trying to get as many stack overflow questions closed/answered as possible... reckon you could answer it yourself with what you just said? – Julian Leviston Apr 28 '14 at 06:05
  • FWIW I'm using jasmine and it's working fine for me. – Julian Leviston Apr 28 '14 at 06:06

0 Answers0