UnitTest for a module using Marionette.CompositeView

I would like to test the behavior of a module (using Marionette ) that works (1).

Oddly enough, js-module (1) works, but 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. }); 
+4
source share
1 answer
 var itemView = new Backbone.View(), collectionView = new Backbone.View(); this.view.appendHtml(collectionView, itemView); 

Sorry, but what do you want to do here? It seems to me that you are adding something to collectionView.$el.find('ul.tasks') while collectionView.$el just empty. Therefore collectionView.$el.find('ul.tasks') returns nothing, etc.

Add console.log() to check this:

 appendHtml: function (collectionView, itemView) { console.log(collectionView.$el.html()); collectionView.$el.find('ul.tasks').append(itemView.el); } 
+3
source

All Articles