Unit test using Marionette.CompositeView

Using jasmine , I am trying to check the javascript module that returns Marionette.CompositeView .

Here is the javascript (2) module and the javascript (1) block test.

My question is: how to access the rendered view from (1)?
See the code comment for more details.

PS:
1) The javascript module works, creating the correct display. 2) When I run the test, the javascript console gives me the following error: backbone.marionette.min.js:9

 Uncaught NoTemplateError: Could not find template: 'function (context, options) { if (!compiled) { compiled = compile(); } return compiled.call(this, context, options); }' 

3) Since I use handlebars , I rewrote Marionette.Renderer.render as follows:

 enter code here define([ 'marionette' ], function (Marionette) { Marionette.Renderer.render = function (template, data) { return template(data); }; }); 

(1)

 (function () { 'use strict'; define([ // some code ], function (MyView) { describe('Layout App - Header View ', function () { beforeEach(function () { this.view = new MyView({ currentUser: new Backbone.Model() }); }); describe('Instantiation', function () { it('should create a div element', function () { expect(this.view.el.nodeName).toEqual('DIV'); // it works }); }); describe("Rendering", function () { it("returns the view object", function () { console.log(this.view.render()); // undefined // why? expect(this.view.render()).toEqual(this.view); // it fails }); }); }); }); }); 

(2)

 define([ // some code ], function (myTemplate, MyItemView) { return Marionette.CompositeView.extend({ template: myTemplate, itemView: MyItemView, // some code }); }); 
+4
source share
2 answers

call the render method on it, as with any other view of the backbone network

 beforeEach(function () { this.view = new MyView({ currentUser: new Backbone.Model() }); // render it this.view.render(); }); 
+1
source

The rendering method does return undefined . Instead of expect(this.view.render()) you should do something like

this.view.render(); expect(this.view.$el.find('.class_in_template').length).to.be.greaterThan(0);

0
source

All Articles