Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fix HTML reporting display to show errors if done is called multiple times, or if an exception is thrown after done is called.

Mark Bannerae4fbca3e190
diff --git a/lib/reporters/html.js b/lib/reporters/html.js
index 62643ecb..27707598 100644
--- a/lib/reporters/html.js
+++ b/lib/reporters/html.js
@@ -129,7 +129,10 @@ function HTML(runner) {
});
runner.on('fail', function(test) {
- if (test.type === 'hook') {
+ // For type = 'test' its possible that the test failed due to multiple
+ // done() calls. So report the issue here.
+ if (test.type === 'hook'
+ || test.type === 'test') {
runner.emit('test end', test);
}
});
diff --git a/test/browser/index.html b/test/browser/index.html
index f10732dd..9200b977 100644
--- a/test/browser/index.html
+++ b/test/browser/index.html
@@ -14,6 +14,7 @@
<script src="array.js"></script>
<script src="../acceptance/duration.js"></script>
<script src="../acceptance/timeout.js"></script>
+ <script src="multiple-done.js"></script>
<script>
onload = function(){
mocha.checkLeaks();
diff --git a/test/browser/multiple-done.js b/test/browser/multiple-done.js
new file mode 100644
index 00000000..d8a9d49a
--- /dev/null
+++ b/test/browser/multiple-done.js
@@ -0,0 +1,16 @@
+describe('Multiple Done calls', function(){
+ it('should report an error if done was called more than once', function(done){
+ done();
+ done();
+ })
+
+ it('should report an error if an exception happened async after done was called', function (done) {
+ done();
+ setTimeout(done, 50);
+ })
+
+ it('should report an error if an exception happened after done was called', function(done){
+ done();
+ throw new Error("thrown error");
+ })
+})