Skip to content

Commit

Permalink
Delegated event callbacks do not have this set correctly #1930
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Aug 16, 2017
1 parent bbc89ea commit 6f66080
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/collection/events.js
Expand Up @@ -24,7 +24,7 @@ let emitterOptions = {
};
},
callbackContext: function( ele, listener, eventObj ){
return listener.selector != null ? eventObj.target : ele;
return listener.qualifier != null ? eventObj.target : ele;
},
beforeEmit: function( context, listener/*, eventObj*/ ){
if( listener.conf && listener.conf.once ){
Expand Down
2 changes: 1 addition & 1 deletion src/core/events.js
Expand Up @@ -24,7 +24,7 @@ let emitterOptions = {
};
},
callbackContext: function( cy, listener, eventObj ){
return listener.selector != null ? eventObj.target : cy;
return listener.qualifier != null ? eventObj.target : cy;
}
};

Expand Down
25 changes: 25 additions & 0 deletions test/events.js
Expand Up @@ -320,6 +320,31 @@ describe('Events', function(){
cy.$('#n5').trigger('foo', ['bar', 'baz']);
});

it('should get the element context when bubbled with a delegate selector on the core', function( done ){
let n4 = cy.$('#n4');

cy.on('foo', 'node', function(){
expect( this[0] === n4[0] ).to.be.true;

done();
});

n4.emit('foo');
});

it('should get the element context when bubbled with a delegate selector on a collection', function( done ){
let n4 = cy.$('#n4');
let n5 = cy.$('#n5');

n4.on('foo', 'node', function(){
expect( this[0] === n5[0] ).to.be.true;

done();
});

n5.emit('foo');
});

});


Expand Down

0 comments on commit 6f66080

Please sign in to comment.