Skip to content

Commit

Permalink
Backport 2.x : Event names with dashes are not recognised #2024
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Nov 17, 2017
1 parent 3c25f20 commit edc7c89
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ var define = {

// event function reusable stuff
event: {
regex: /(\w+)(\.(?:\w+|\*))?/, // regex for matching event strings (e.g. "click.namespace")
regex: /([^.]+)(\.(?:[^.]+|\*))?/, // regex for matching event strings (e.g. "click.namespace")
universalNamespace: '.*', // matches as if no namespace specified and prevents users from unbinding accidentally
optionalTypeRegex: /(\w+)?(\.(?:\w+|\*))?/,
optionalTypeRegex: /([^.]+)?(\.(?:[^.]+|\*))?/,
falseCallback: function(){ return false; }
},

Expand Down
135 changes: 135 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,73 @@ describe('Events', function(){

});

it('allows dash in event name', function(){
var foo = false;
var fooBar = false;

cy.on('foo-bar');

cy.on('foo', function(){ foo = true; });

cy.on('foo-bar', function(){ fooBar = true; });

cy.emit('foo-bar');

expect(foo).to.be.false;
expect(fooBar).to.be.true;
});

it('allows underscore in event namespace', function(){
var bar = false;
var barBaz = false;
var foo = false;

cy.on('foo.bar', function(){ bar = true; });

cy.on('foo.bar-baz', function(){ barBaz = true; });

cy.on('foo', function(){ foo = true; });

cy.emit('foo.bar-baz');

expect(foo, 'foo').to.be.true;
expect(bar, 'foo.bar').to.be.false;
expect(barBaz, 'foo.bar-baz').to.be.true;
});

it('allows dash in event name', function(){
var foo = false;
var fooBar = false;

cy.on('foo_bar');

cy.on('foo', function(){ foo = true; });

cy.on('foo_bar', function(){ fooBar = true; });

cy.emit('foo_bar');

expect(foo).to.be.false;
expect(fooBar).to.be.true;
});

it('allows underscore in event namespace', function(){
var bar = false;
var barBaz = false;
var foo = false;

cy.on('foo.bar', function(){ bar = true; });

cy.on('foo.bar_baz', function(){ barBaz = true; });

cy.on('foo', function(){ foo = true; });

cy.emit('foo.bar_baz');

expect(foo, 'foo').to.be.true;
expect(bar, 'foo.bar').to.be.false;
expect(barBaz, 'foo.bar_baz').to.be.true;
});
});

describe('cy.one()', function(){
Expand Down Expand Up @@ -676,6 +743,74 @@ describe('Events', function(){
expect(inner, 'inner').to.be.false;
});

it('allows dash in event name', function(){
var n = cy.nodes()[0];
var foo = false;
var fooBar = false;

n.on('foo', function(){ foo = true; });

n.on('foo-bar', function(){ fooBar = true; });

n.emit('foo-bar');

expect(foo).to.be.false;
expect(fooBar).to.be.true;
});

it('allows dash in event namespace', function(){
var n = cy.nodes()[0];
var bar = false;
var barBaz = false;
var foo = false;

n.on('foo.bar', function(){ bar = true; });

n.on('foo.bar-baz', function(){ barBaz = true; });

n.on('foo', function(){ foo = true; });

n.emit('foo.bar-baz');

expect(foo, 'foo').to.be.true;
expect(bar, 'foo.bar').to.be.false;
expect(barBaz, 'foo.bar-baz').to.be.true;
});

it('allows underscore in event name', function(){
var n = cy.nodes()[0];
var foo = false;
var fooBar = false;

n.on('foo', function(){ foo = true; });

n.on('foo_bar', function(){ fooBar = true; });

n.emit('foo_bar');

expect(foo).to.be.false;
expect(fooBar).to.be.true;
});

it('allows underscore in event namespace', function(){
var n = cy.nodes()[0];
var bar = false;
var barBaz = false;
var foo = false;

n.on('foo.bar', function(){ bar = true; });

n.on('foo.bar_baz', function(){ barBaz = true; });

n.on('foo', function(){ foo = true; });

n.emit('foo.bar_baz');

expect(foo, 'foo').to.be.true;
expect(bar, 'foo.bar').to.be.false;
expect(barBaz, 'foo.bar_baz').to.be.true;
});

});

describe('eles.one()', function(){
Expand Down

0 comments on commit edc7c89

Please sign in to comment.