Phillip Whisenhunt
Phillip Whisenhunt

Reputation: 1305

Jasmine not finding Backbone.js Models

I've just started using Jasmine with maven. I have Jasmine working, but for some reason it cannot find my Backbone models. I have the JavaScript src directory pointing to the folder containing my Backbone.js models. In my JavaScript test directory I have a simple test as such:

describe('ToDo Model',function()
{
    it('Test',function() {
        var todo = new ToDo();
    });
});

But I keep getting ToDo is not defined. Do I have to write my tests inside of the my backbone model files or anything? Thanks.

Upvotes: 0

Views: 336

Answers (2)

clem
clem

Reputation: 3534

It's usually a good practice to define a global namespace for your app, for example:

window.Application = {
  Models: {},
  Views: {},
  Collections: {}
}

// etc.

Then, I like to define models like this:

(function (Models) {
  Models.ToDo = Backbone.Models.extend({
    // etc...
  });
})(Application.Models);

The namespacing here isn't necessary, but seeing Models right at the top of the file is a nice visual cue, I think.

Upvotes: 1

Paolo del Mundo
Paolo del Mundo

Reputation: 2121

ToDo has to be in the global namespace as well. Try typing this in your Chrome/Firefox console:

window.ToDo

If it returns undefined, then that's the problem!

Upvotes: 2

Related Questions