poseid
poseid

Reputation: 7156

How to setup Jasmine with RequireJS?

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

Upvotes: 1

Views: 1932

Answers (2)

skusunam
skusunam

Reputation: 411

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.

Upvotes: 0

Chris A
Chris A

Reputation: 368

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

Upvotes: 2

Related Questions