Permalink
Browse files

Adding tests for `onListenerError` option.

  • Loading branch information...
domenic committed Feb 3, 2012
1 parent cb31ed9 commit 78aef32228a6ae974b3d56b988a76b30af697ec3
Showing with 18 additions and 5 deletions.
  1. +0 −2 lib/Publisher.js
  2. +18 −3 test/3 options.coffee
View
@@ -12,8 +12,6 @@ function normalizeOptions(options) {
}
if (options.onListenerError === undefined) {
- // TODO: test this, somehow!!
- // http://stackoverflow.com/questions/9025095/how-can-i-test-uncaught-errors-in-mocha
options.onListenerError = function (error) {
process.nextTick(function () {
throw error;
View
@@ -8,14 +8,29 @@ describe "Publisher options", ->
emitter = null
describe "onListenerError", ->
- onListenerError = null
+ it "should by default re-throw listeners errors in the next turn of the event loop", (next) ->
+ publisher = new Publisher()
+ emitter = publisher.emitter
- beforeEach ->
+ error = new Error("Boo")
+ emitter.on("eventName", -> throw error)
+
+ onUncaughtException = sinon.spy()
+ originalOnUncaughtException = process.listeners("uncaughtException").pop()
+ process.once("uncaughtException", onUncaughtException)
+
+ publisher.publish("eventName")
+
+ process.nextTick ->
+ process.listeners("uncaughtException").push(originalOnUncaughtException)
+ sinon.assert.calledWith(onUncaughtException, error)
+ next()
+
+ it "should deliver errors thrown by listeners to the supplied callback", ->
onListenerError = sinon.spy()
publisher = new Publisher(onListenerError: onListenerError)
emitter = publisher.emitter
- it "should deliver errors thrown by listeners to the supplied callback", ->
error = new Error("Boo")
emitter.on("eventName", -> throw error)

0 comments on commit 78aef32

Please sign in to comment.