I'm using Jasmine for unit testing to test an application with Backbone.js (and it's the first time that I'm working with them both so I'm a little bit stuck :/ ) Here is my Backbone view
define(['jquery','backbone','underscore','handelbars','models/story','text!templates/story.html',
'controllers/storyController'],
function($, Backbone, _,handelbars, story,storyTemplate,ctrl){
var View = Backbone.View.extend({
el: '#main',
events:{
'click .close-story' : 'closeStory',
}
// Some functions
});
return View;
});
and the spec of Jasmine
define(['views/storyView'],function (storyView) {
describe("Testing the Story View ",function () {
var stView;
beforeEach(function(){
stView=new storyView({id:1});
stView.render();
})
it("Test if el is defined and trigger the click ",function () {
expect(stView.el).toBeDefined();
})
})
})
Thank you :)
myView.render().el
as mentioned in title. Why are you clicking the button in test beforeexpect(stView.$el.find('.addbtn')).toBeDefined();
? Why do you needvar self = this;
in the shared code? Why are you using$(self.el)
instead ofself.$el
? In short, please cleanup your code, post proper error and if possible create a minimal reproducible exampleel
property ofrender
method as you mentioned in the error in title:myView.render().el
. So the code causing the issue is not present in question, and the content of render function is also not there in question... So we can't figure out what's the problem without seeing the code...stView.render().el
yet your test testsexpect(stView.el).toBeDefined()
. On the basis of the title, I'd expect the test to beexpect(stView.render().el).toBeDefined()
. It is still not clear what the problem is exactly, given the inconsistency between the title and code you show. Answers will also most likely depend on the implementation ofrender()
, which as TJ pointed out already, you do not show.