Skip to content

Commit

Permalink
Merge pull request #1981 from Standard8/fix-done-reporting-on-html
Browse files Browse the repository at this point in the history
Fix HTML reporting display to show errors if done is called multiple times, or if an exception is thrown after done is called.
  • Loading branch information
danielstjules committed Dec 25, 2015
2 parents 9d8c154 + ae4fbca commit 829df1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
1 change: 1 addition & 0 deletions test/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions test/browser/multiple-done.js
Original file line number Diff line number Diff line change
@@ -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");
})
})

0 comments on commit 829df1d

Please sign in to comment.