Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Added test to assert that custom events do work correctly (fixes #78)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangemug committed Dec 7, 2016
1 parent 709dfc8 commit c446f7c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/tests/delegateTest.js
Expand Up @@ -12,6 +12,7 @@ setupHelper.setUp = function() {
'<div id="container1">'
+ '<div id="delegate-test-clickable" class="delegate-test-clickable"></div>'
+ '<div id="another-delegate-test-clickable"><input id="js-input" /></div>'
+ '<div id="custom-event"></div>'
+ '</div>'
+ '<div id="container2">'
+ '<div id="element-in-container2-test-clickable" class="delegate-test-clickable"></div>'
Expand Down Expand Up @@ -59,6 +60,13 @@ setupHelper.fireFormEvent = function (target, eventName) {
}
};

setupHelper.fireCustomEvent = function(target, eventName) {
var ev = new Event(eventName, {
bubbles: true
});
target.dispatchEvent(ev);
};

buster.testCase('Delegate', {
'setUp': function() {
setupHelper.setUp();
Expand Down Expand Up @@ -604,6 +612,25 @@ buster.testCase('Delegate', {
assert.calledOnce(bubbleSpy);
},

'Custom events are supported': function() {
var delegate = new Delegate(document.body);
var spyOnContainer = this.spy();
var spyOnElement = this.spy();

delegate.on('foobar', '#container1', function(event) {
spyOnContainer();
});

delegate.on('foobar', '#custom-event', function(event) {
spyOnElement();
});

setupHelper.fireCustomEvent(document.getElementById("custom-event"), 'foobar');

assert.calledOnce(spyOnContainer);
assert.calledOnce(spyOnElement);
},

'tearDown': function() {
setupHelper.tearDown();
}
Expand Down

0 comments on commit c446f7c

Please sign in to comment.