1

I am having a problem to figure out how to setup Jasmine with modules from RequireJS.

Basically, I want to test a first view:

it("can load sandbox", function() {
  var view = new ItemView();
  node = view.render().el;
  expect(node).toContain("<li>Test</li>");
});

I don't see that ItemView can be defined as Backbone view, or how to inject Backbone into my tests with requirejs. Now, I see some discussions on using testr.js on one hand, on the other hand, I've found a git repo that does a setup of SpecRunner.js : http://github.com/uzikilon/Todos.git

Ideally, I would just be running

rake jasmine

from my project directory, but how would should Jasmine and Require.js be talking to each other?

Many thanks if someone has feedback, eventually, with a pull request on this experimental repo: https://github.com/mulderp/backbone-require-test

poseid
  • 6,986
  • 10
  • 48
  • 78
  • 1
    Hi, there's an example in the Backbone-Boilerplate project here: https://github.com/tbranyen/backbone-boilerplate/blob/master/test/jasmine/index.html – Simon Boudrias Dec 17 '12 at 01:29
  • 1
    Take a look at this SO? http://stackoverflow.com/q/11439540/184883 – Andreas Köberle Dec 17 '12 at 11:10
  • I am now looking into requireDependencies helper: https://github.com/mulderp/backbone-require-test/blob/master/spec/itemViewSpec.js – poseid Dec 18 '12 at 09:44

2 Answers2

2

Uzi Kilon, who is the author of the github repo you linked to, wrote an article about how to set the two up together, here.

The other part of your question seems to suggest you want to automate the running of the tests, one way to do that is using PhantomJS the headless webkit implementation. You'll find an article about that here

Chris A
  • 368
  • 1
  • 8
  • thanks, I wrote a blog post here: http://pmulder.blogspot.de/2012/12/reflections-on-using-jasmine-for-dom.html – poseid Dec 18 '12 at 22:20
  • Ah, excellent inclusion of the webdriver stuff. I knew there was a way to do that but couldn't remember the tool needed. Very useful. – Chris A Dec 24 '12 at 10:46
0

How is backbone.js is getting loaded in your ItemView? If you define require.js configuration that could be shared between your production code and Jasmine tests. Again there are different ways developers do to achieve this.

skusunam
  • 411
  • 3
  • 12