Permalink
Browse files

fix return value of emit for onAny() listeners, and add test cases

  • Loading branch information...
1 parent 0e8e232 commit f508cc107b2088cb3ae5b2e48f748f8414c0644b @pwellner pwellner committed Mar 12, 2012
Showing with 40 additions and 3 deletions.
  1. +2 −2 lib/eventemitter2.js
  2. +18 −1 test/simple/emit.js
  3. +20 −0 test/wildcardEvents/addListener.js
View
@@ -318,10 +318,10 @@
this.event = type;
listeners[i].apply(this, args);
}
- return listeners.length > 0;
+ return (listeners.length > 0) || this._all;
}
else {
- return false;
+ return this._all;
}
};
View
@@ -130,7 +130,24 @@ module.exports = simpleEvents({
test.expect(16);
test.done();
- }
+ },
+ '6. Check return values of emit.': function (test) {
+
+ var emitter = this.emitter;
+
+ function functionA() { test.ok(true, 'The event was raised'); }
+
+ emitter.on('test6', functionA);
+
+ test.ok(emitter.emit('test6'), 'emit should return true after calling a listener');
+ test.ok(!emitter.emit('other'), 'emit should return false when no listener was called');
+
+ emitter.onAny(functionA);
+ test.ok(emitter.emit('other'), 'emit should return true after calling an onAny() listener');
+
+ test.expect(5);
+ test.done();
+ },
});
@@ -283,5 +283,25 @@ module.exports = simpleEvents({
test.expect(58);
test.done();
+ },
+
+ '12. Check return values of emit for wildcard emitter.': function (test) {
+
+ var emitter = this.emitter;
+
+ emitter.on('foo.*', function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ emitter.onAny(function () {
+ test.ok(true, 'The event was raised');
+ });
+
+ test.ok(emitter.emit('foo.blah'), 'emit should return true after calling a listener');
+ test.ok(emitter.emit('bar'), 'emit should return true after calling a listener');
+
+ test.expect(5);
+ test.done();
}
+
});

0 comments on commit f508cc1

Please sign in to comment.