Skip to content

Commit

Permalink
fixed typo, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpincin committed Mar 16, 2016
1 parent 725752d commit f3676d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 6 additions & 5 deletions constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ function produce (data) {
function produceError (err) {
if (this._destroyed)
throw new EventuateDestroyedError('unable to produce after destroy', err)
if (!this.listeners('error', true))
throw (err instanceof err) ? err : new EventuateUnconsumedError(err)
if (!this.listeners('error', true)) throw (err instanceof Error)
? err
: new EventuateUnconsumedError(err)
this.emit('error', err)
}

Expand Down Expand Up @@ -128,8 +129,8 @@ function consume (consumer, errConsumer) {
var consumption = new Consumption(this, consumer, errConsumer)
return consumption

function onConsumerRemoved (emoved) {
if (emoved === consumer) {
function onConsumerRemoved (removed) {
if (removed === consumer) {
if (errConsumer)
this.removeListener('error', errConsumer)
consumption.emit('end')
Expand All @@ -145,7 +146,7 @@ function consume (consumer, errConsumer) {
function hasConsumer (consumer) {
return consumer
? this.listeners('data').indexOf(consumer) > -1
: this.listeners('data', true) > 0
: this.listeners('data', true)
}

function consumers () {
Expand Down
6 changes: 5 additions & 1 deletion test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ test('cannot produceError after destroyed', timeout, function (t) {
})

test('produce string err with no errorConsumer throws', timeout, function (t) {
t.plan(1)
t.plan(2)
var event = eventuate()
t.throws(function () {
event.produceError('boom')
}, Error, 'throws Error')

t.throws(function () {
event.produceError(new Error('boom'))
}, Error, 'throws Error')
})

test('err thrown for invalid errConsumer', timeout, function (t) {
Expand Down

0 comments on commit f3676d4

Please sign in to comment.