Reputation: 1
I have a simple Backbone View and a simple unit test written in Mocha.
View code:
var MyView = Backbone.View.extend({
el: '#myDiv',
initialize: function(options) {
if(options.model)
this.model = options.model;
}
});
My test code:
var view;
describe('myView Test', function(){
before(function(done){
view = new MyView();
});
});
When I try to create a new View, I receive;
Application View "before all" hook:
TypeError: Expecting a function in instanceof check, but got #myDiv
at backbone.js line 1203
I am not so sure what is missing here, any insights?
Thank you, sakal
Upvotes: 0
Views: 1357
Reputation: 431
I see a couple of things wrong here.
First, as @Aron-Woost mentioned, you are having the before hook run asynchronously. If this is what you want to do, you need to call done();
at the end of hook or you will get a timeout error. If you want to run the hook synchronously, don't pass the done
argument into the function.
Next, when you are initializing your view in the before all
hook you are not passing an options object argument. Not having this should cause an error in your backbone view. Since options
is not being passed in, you should be getting an error on the if
statement along the lines of Cannot read property 'model' of undefined
. Easy fix for this, pass as empty object{}
so you have something like this: view = new MyView({});
.
Not sure how you are producing the exact error you have listed above. Have you provided all of your code for this problem?
Upvotes: 2