Skip to content

Commit

Permalink
Fix delegateEvents + behavior bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jonknapp authored and samccone committed Jan 14, 2015
1 parent 4326f5c commit 5543493
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ Marionette.Behaviors = (function(Marionette, _) {

behaviorEvents: function(behaviorEvents, behaviors) {
var _behaviorsEvents = {};
var viewUI = _.result(this, 'ui');
var viewUI = this._uiBindings || _.result(this, 'ui');

_.each(behaviors, function(b, i) {
var _events = {};
var behaviorEvents = _.clone(_.result(b, 'events')) || {};
var behaviorUI = _.result(b, 'ui');
var behaviorUI = b._uiBindings || _.result(b, 'ui');

// Construct an internal UI hash first using
// the views UI hash and then the behaviors UI hash.
Expand Down
6 changes: 6 additions & 0 deletions test/unit/behaviors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ describe('Behaviors', function() {
expect(this.behaviors.foo.prototype.events).to.have.property('click @ui.bar', 'onBarClick');
});

it('should handle click events after calling delegateEvents', function() {
this.view.delegateEvents();
expect(this.fooBehavior.ui.foo.click.bind(this.view.ui.bar)).to.not.throw(Error);
expect(this.view.ui.bar.click.bind(this.view.ui.bar)).to.not.throw(Error);
});

it('should set the behavior UI element', function() {
expect(this.onRenderStub).to.have.been.calledOnce;
});
Expand Down

0 comments on commit 5543493

Please sign in to comment.