Skip to content

Commit 6eff031

Browse files
committed
Merge pull request #169 from jxc876/gh-pages
Test case for $.unbind #166 #156
2 parents 7105e51 + b8a4545 commit 6eff031

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/events/UnbindSpec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
describe("$.unbind", function () {
2+
3+
helpers.fixture('events.html');
4+
5+
it('exists', function () {
6+
expect($.unbind).to.exist;
7+
});
8+
9+
it("unbind events using namespaces", function (done) {
10+
// Setup
11+
var subject = document.querySelector("#simpleDiv");
12+
13+
var spy1 = sinon.spy();
14+
var spy2 = sinon.spy();
15+
var spy3 = sinon.spy();
16+
17+
subject.addEventListener('click.namespace1.foo', spy1);
18+
subject.addEventListener('click.namespace1.bar', spy2);
19+
subject.addEventListener('click.namespace2.bar', spy3);
20+
21+
// Exercise
22+
$.unbind(subject, '.namespace1');
23+
fireEvent(subject, 'click');
24+
25+
// Verify
26+
expect(spy1.notCalled).to.be.ok;
27+
expect(spy2.notCalled).to.be.ok;
28+
expect(spy3.calledOnce).to.be.ok;
29+
30+
done();
31+
});
32+
33+
function fireEvent(target, eventName) {
34+
var event = new Event(eventName, {'bubbles': true, 'cancelable': true});
35+
target.dispatchEvent(event);
36+
}
37+
38+
});

0 commit comments

Comments
 (0)