Skip to content

Commit

Permalink
Merge pull request #169 from jxc876/gh-pages
Browse files Browse the repository at this point in the history
Test case for $.unbind #166 #156
  • Loading branch information
LeaVerou committed Feb 17, 2016
2 parents 7105e51 + b8a4545 commit 6eff031
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/events/UnbindSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("$.unbind", function () {

helpers.fixture('events.html');

it('exists', function () {
expect($.unbind).to.exist;
});

it("unbind events using namespaces", function (done) {
// Setup
var subject = document.querySelector("#simpleDiv");

var spy1 = sinon.spy();
var spy2 = sinon.spy();
var spy3 = sinon.spy();

subject.addEventListener('click.namespace1.foo', spy1);
subject.addEventListener('click.namespace1.bar', spy2);
subject.addEventListener('click.namespace2.bar', spy3);

// Exercise
$.unbind(subject, '.namespace1');
fireEvent(subject, 'click');

// Verify
expect(spy1.notCalled).to.be.ok;
expect(spy2.notCalled).to.be.ok;
expect(spy3.calledOnce).to.be.ok;

done();
});

function fireEvent(target, eventName) {
var event = new Event(eventName, {'bubbles': true, 'cancelable': true});
target.dispatchEvent(event);
}

});

0 comments on commit 6eff031

Please sign in to comment.