Unit test with a Marionette.CompositeView

By using jasmine, I am trying to test a javascript module which returns a Marionette.CompositeView.

Here are the javascript module(2) and the javascript unit-test(1).

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

P.S.: 1) The javascript module works producing the right rendered view. 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 am using handlebars I rewrote the Marionette.Renderer.render in this way:

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
    });

});

Answers


call the render method on it, like you would with any other backbone view

            beforeEach(function () {
                this.view = new MyView({
                    currentUser: new Backbone.Model()
                });

                // render it
                this.view.render();
            });

The render method does, in fact, 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);


Need Your Help

iOS undefined symbol errors linking with libOmnitureAppMeasurement-iPhoneSimulator.a

ios ios-simulator adobe-analytics undefined-symbol i386

I'm building app usage tracking into an iOS iPad app (iOS 6.1 and newer) using the Omniture App Measurement libraries.

How can I cancel a UIScrollView zoom bounce?

objective-c cocoa-touch uiscrollview zoom bounce

I'm using a zooming UIScrollView to show images in my iPad app. The zooming works great, with a pinch making an image smaller or bigger as appropriate. I also have bouncesZoom enabled so that it bo...