Skip to content

Commit

Permalink
Event names with dashes are not recognised #2022
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Nov 17, 2017
1 parent d7b1253 commit 3d4d975
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/emitter.js
Expand Up @@ -2,7 +2,7 @@ const util = require('./util');
const is = require('./is');
const Event = require('./event');

const eventRegex = /(\w+)(\.(?:\w+|\*))?/; // regex for matching event strings (e.g. "click.namespace")
const eventRegex = /^([^.]+)(\.(?:[^.]+))?$/; // regex for matching event strings (e.g. "click.namespace")
const universalNamespace = '.*'; // matches as if no namespace specified and prevents users from unbinding accidentally

const defaults = {
Expand Down
135 changes: 135 additions & 0 deletions test/events.js
Expand Up @@ -426,6 +426,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 @@ -668,6 +735,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 3d4d975

Please sign in to comment.