Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

test for multiple calls

Tj Holowaychukefc235049f6c
diff --git a/lib/runnable.js b/lib/runnable.js
index 217d9ab5..7b95effa 100644
--- a/lib/runnable.js
+++ b/lib/runnable.js
@@ -1,4 +1,10 @@
+/**
+ * Module dependencies.
+ */
+
+var EventEmitter = require('events').EventEmitter;
+
/**
* Expose `Runnable`.
*/
@@ -21,6 +27,12 @@ function Runnable(title, fn) {
this.timeout(2000);
}
+/**
+ * Inherit from `EventEmitter.prototype`.
+ */
+
+Runnable.prototype.__proto__ = EventEmitter.prototype;
+
/**
* Set & get timeout `ms`.
*
diff --git a/test/runnable.js b/test/runnable.js
index 0ead33ae..67ab9b96 100644
--- a/test/runnable.js
+++ b/test/runnable.js
@@ -90,6 +90,31 @@ describe('Runnable(title, fn)', function(){
})
})
+ describe('when the callback is invoked several times', function(){
+ describe('without an error', function(){
+ it('should emit a single "error" event', function(done){
+ var calls = 0;
+ var errCalls = 0;
+
+ var test = new Runnable('foo', function(done){
+ process.nextTick(done);
+ process.nextTick(done);
+ process.nextTick(done);
+ });
+
+ test.on('error', function(err){
+ ++errCalls;
+ console.log(err);
+ });
+
+ test.run(function(){
+ ++calls;
+ console.log('called');
+ });
+ })
+ })
+ })
+
describe('when an exception is thrown', function(){
it('should invoke the callback', function(done){
var calls = 0;