mardi 3 novembre 2015

How to cover Marionette View's event using test cases of Jasmine?

I am working on Test cases for Marionette's View. By using events attribute, I have written a callback function on click of an HTML element. The functionality is working but I am struggling in writing test cases. I am not able to cover that click event using Jasmine test cases.

I have used the Marionette Region to render the view. I have tried using spies but those are not working.

Please find code snippet below for more details:

var TestView = Backbone.Marionette.CompositeView.extend({
     tagName: 'div',
        className: 'test-menu',
        childView: testMenuView,
        childViewOptions: function() {
            return {
                'componentId': this.cid
            };
        },
        template: _.template(testTemplate),
        initialize: function(options) {
            this.collection = this.options.testData;
        },
        onShow: function(collectionView) {
            collectionView.$el.show();
        },            
       attachHtml: function(collectionView,itemView) {
         collectionView.$("#testMenu").append(itemView.el);
       },
        events: {
            'click #testBtn': function (event) {
                    alert('testBtn Clicked');
            }
        }
    });

Aucun commentaire:

Enregistrer un commentaire