title: Jasmine expected spy function to have been called on backbone.view
body: <p>I am having trouble understanding spies with my jasmine tests.</p>
  
  <p>When I run the below test I can see the output <code>CLOSE EVENT</code> in my console, but the test <code>triggers close</code> fails.</p>
  
  <p>How do I write the test correctly using spies?</p>
  
  <pre><code>define([
      'backbone'
  ], function(Backbone){
      describe('TEST', function(){
          beforeEach(function(){
              this.view = new (Backbone.View.extend({
                  initialize: function(){
                      _(this).bindAll('close');
                      this.$el.append($('&lt;span&gt;', {class: 'closeview'}));
                      $('body').append(this.$el);
                      this.$el.on('click', '.closeview', this.close);
                  },
                  close: function(){
                      console.log('CLOSE EVENT');
                  }
              }));
          });
          it('exists', function(){
              expect(this.view.$el).toBeVisible();
          });
          it('triggers close', function(){
              spyOn(this.view, 'close');
              this.view.$el.find('.closeview').trigger('click');
              expect(this.view.close).toHaveBeenCalled();
          });
      });
  });
  </code></pre>