Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Nov 4, 2019
1 parent a2d16ec commit 8b1138a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
@@ -0,0 +1,12 @@
'use strict';

describe('Uncaught exception - throw and exit', () => {
it('test1', () => {
setTimeout(() => {
throw new Error('Uncaught error after test1');
}, 1);
});
it('test2', function () { });
it('test3', function () { });
it('test4', function () { });
});
15 changes: 15 additions & 0 deletions test/integration/fixtures/uncaught-pending.fixture.js
@@ -0,0 +1,15 @@
'use strict';

describe('Uncaught exception within pending test', () => {
it('test1', function () { });

it('test2', function () {
process.nextTick(function () {
throw new Error('I am uncaught!');
});
this.skip();
});

it('test3 - should run', function () { });
it('test4 - should run', function () { });
});
21 changes: 21 additions & 0 deletions test/integration/options/allowUncaught.spec.js
Expand Up @@ -2,11 +2,32 @@

var path = require('path').posix;
var helpers = require('../helpers');
var runMocha = helpers.runMocha;
var runMochaJSON = helpers.runMochaJSON;

describe('--allow-uncaught', function() {
var args = ['--allow-uncaught'];

it('should throw an uncaught error and exit process', function(done) {
var fixture = path.join('options', 'allow-uncaught', 'propagate');
runMocha(
fixture,
args,
function(err, res) {
if (err) {
return done(err);
}

expect(res.code, 'to be greater than', 0);
expect(res.output, 'to contain', 'Error: Uncaught error after test1');
expect(res.passing, 'to be', 0);
expect(res.failing, 'to be', 0);
done();
},
{stdio: 'pipe'}
);
});

it('should run with conditional `this.skip()`', function(done) {
var fixture = path.join('options', 'allow-uncaught', 'this-skip-it');
runMochaJSON(fixture, args, function(err, res) {
Expand Down
23 changes: 23 additions & 0 deletions test/integration/uncaught.spec.js
Expand Up @@ -63,4 +63,27 @@ describe('uncaught exceptions', function() {
done();
});
});

it('handles uncaught exceptions within pending tests', function(done) {
run('uncaught-pending.fixture.js', args, function(err, res) {
if (err) {
return done(err);
}

expect(res, 'to have failed')
.and('to have passed test count', 3)
.and('to have pending test count', 1)
.and('to have failed test count', 1)
.and(
'to have passed test',
'test1',
'test3 - should run',
'test4 - should run'
)
.and('to have pending test order', 'test2')
.and('to have failed test', 'test2');

done();
});
});
});

0 comments on commit 8b1138a

Please sign in to comment.