Reputation: 13400
I would like to test the behaviour of a module (using Marionette) which works (1).
Oddly, the js-module (1) works but the unit test (2) using Jasmine fails.
Any ideas?
(1)
/*global define*/
define([
'marionette',
'tasks/views/item',
'text!tasks/templates/list.html',
'collections/tasks'
], function (Marionette, itemView, listTemplate, TaskCollection) {
"use strict";
var ListView = Marionette.CompositeView.extend({
initialize: function () {
this.collection = new TaskCollection();
this.collection.fetch();
},
template: listTemplate,
itemView: itemView,
appendHtml: function (collectionView, itemView) {
collectionView.$el.find('ul.tasks').append(itemView.el);
}
});
return ListView;
});
(2)
// spec file
it("should add a new element", function () {
// TODO
var itemView = new Backbone.View(),
collectionView = new Backbone.View();
this.view.appendHtml(collectionView, itemView);
expect(this.view.$el.find('ul.tasks').length).toEqual(1);
// Expected 0 to equal 1.
});
Upvotes: 4
Views: 564
Reputation: 2702
var itemView = new Backbone.View(),
collectionView = new Backbone.View();
this.view.appendHtml(collectionView, itemView);
Sorry, but what do you want to accomplish here? It seems to me you append something to collectionView.$el.find('ul.tasks')
at the moment, when collectionView.$el
is just empty. So collectionView.$el.find('ul.tasks')
returns nothing and so on.
Add console.log()
to check this:
appendHtml: function (collectionView, itemView) {
console.log(collectionView.$el.html());
collectionView.$el.find('ul.tasks').append(itemView.el);
}
Upvotes: 3