From b8a454537b2f0d239c2e1dcb0af712e5b300bd09 Mon Sep 17 00:00:00 2001 From: jxc876 Date: Tue, 16 Feb 2016 22:35:49 -0600 Subject: [PATCH] Test case for $.unbind #166 #156 --- tests/events/UnbindSpec.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/events/UnbindSpec.js diff --git a/tests/events/UnbindSpec.js b/tests/events/UnbindSpec.js new file mode 100644 index 0000000..bbb8757 --- /dev/null +++ b/tests/events/UnbindSpec.js @@ -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); + } + +});