Skip to content

Commit

Permalink
Merge pull request #6 from blocks/add-options-obj-to-events
Browse files Browse the repository at this point in the history
Add options obj to events
  • Loading branch information
localjo committed Feb 5, 2015
2 parents a33a91f + e629b31 commit 2da8f06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/alerter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Alerter.prototype.create = function (options) {
tempDiv.outerHTML = this.template(options);
var alert = document.getElementById(options.id);

this.emit('alertCreated', alert);
this.emit('alertCreated', alert, options);

var closeButton = alert.querySelector('.alert__close-button');

Expand Down
18 changes: 15 additions & 3 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ describe('Alerter Module', function() {
});

describe('Events', function() {
it('Emits events', function(done){
it('alertCreated event fires on Alerter.create with HTMLElement, options object', function(done){
var myAlerter = new Alerter({
prependTo: '#test-element'
});
var spy = sinon.spy(myAlerter, 'emit');
var myListener = sinon.spy();
myAlerter.on('alertCreated', myListener);
myAlerter.create({message: 'test'});
assert(spy.called);
assert(myListener.calledWith(sinon.match.has('tagName'), sinon.match({message: 'test'})));
done();
});
it('alertDismissed event fires on Alerter.dismiss with HTMLElement', function(done){
var myAlerter = new Alerter({
prependTo: '#test-element'
});
var myListener = sinon.spy();
myAlerter.on('alertDismissed', myListener);
myAlerter.create({message: 'test'});
myAlerter.dismiss();
assert(myListener.calledWith(sinon.match.has('tagName')));
done();
});
});
Expand Down

0 comments on commit 2da8f06

Please sign in to comment.