eventemitter-ex
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -270,2 +270,10 @@ 'use strict'; | ||
EventEmitterEx.fromPromise = function fromPromise (promise) { | ||
var eex = new EventEmitterEx(); | ||
promise.then(eex.emit.bind(eex, 'end'), eex.emit.bind(eex, 'error')); | ||
return eex; | ||
}; | ||
function assertIsFunction (f) { | ||
@@ -272,0 +280,0 @@ if (typeof f !== 'function') |
{ | ||
"name": "eventemitter-ex", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "EventEmitter extensions", | ||
@@ -5,0 +5,0 @@ "main": "EventEmitterEx.js", |
@@ -68,2 +68,32 @@ 'use strict'; | ||
describe('#fromPromise()', function () { | ||
it('should emit end when promise is resolved', function (done) { | ||
var p = Promise.resolve(42); | ||
var eex = EEX.fromPromise(p); | ||
eex | ||
.on('end', function (res) { | ||
res.should.equal(42); | ||
done(); | ||
}) | ||
.on('error', done); | ||
}); | ||
it('should emit error when promise is rejected', function (done) { | ||
var ERROR = new Error('Boom!'); | ||
var p = Promise.reject(ERROR); | ||
var eex = EEX.fromPromise(p); | ||
eex | ||
.on('error', function (err) { | ||
err.should.equal(ERROR); | ||
done(); | ||
}) | ||
.on('end', function () { | ||
done(new Error('WTF?')); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -70,0 +100,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58364
939