diff --git a/test/integration/fixtures/uncaught/recover.fixture.js b/test/integration/fixtures/uncaught/recover.fixture.js new file mode 100644 index 0000000000..12e346dafe --- /dev/null +++ b/test/integration/fixtures/uncaught/recover.fixture.js @@ -0,0 +1,25 @@ +'use strict'; +const assert = require('assert'); + +describe('uncaught', function() { + var hookOrder = []; + it('throw delayed error', (done) => { + setTimeout(() => { + throw new Error('Whoops!'); + }, 10) + setTimeout(done, 10); + }); + it('should wait 15 ms', (done) => { + setTimeout(done, 15); + }); + it('test 3', () => { }); + + afterEach(function() { + hookOrder.push('afterEach'); + }); + after(function() { + hookOrder.push('after'); + assert.deepEqual(hookOrder, ['afterEach', 'afterEach', 'afterEach', 'after']); + throw new Error('should get upto here and throw'); + }); +}); diff --git a/test/integration/uncaught.spec.js b/test/integration/uncaught.spec.js index 001c89429a..55920f3b31 100644 --- a/test/integration/uncaught.spec.js +++ b/test/integration/uncaught.spec.js @@ -87,6 +87,33 @@ describe('uncaught exceptions', function() { }); }); + it('handles uncaught exceptions within open tests', function(done) { + run('uncaught/recover.fixture.js', args, function(err, res) { + if (err) { + return done(err); + } + + expect( + res, + 'to have failed with error', + 'Whoops!', + 'Whoops!', // JSON reporter does not show the second error message + 'should get upto here and throw' + ) + .and('to have passed test count', 2) + .and('to have failed test count', 3) + .and('to have passed test', 'should wait 15 ms', 'test 3') + .and( + 'to have failed test', + 'throw delayed error', + 'throw delayed error', + '"after all" hook for "test 3"' + ); + + done(); + }); + }); + it('removes uncaught exceptions handlers correctly', function(done) { run('uncaught/listeners.fixture.js', args, function(err, res) { if (err) {