Skip to content

Commit

Permalink
extend existing tests, additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Apr 22, 2020
1 parent 434e823 commit 9bd10b3
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

describe('spec 1', function () {
it('should run test-1', function () { });

describe('nested spec 2', function () {
beforeEach(function (done) {
process.nextTick(function () {
throw new Error('before each hook error');
});
});
it('should not run nested test-2', function () { });

describe('deepnested spec 3', function () {
it('should not run deepnested test-3', function () { });
});
});
});
15 changes: 15 additions & 0 deletions test/integration/fixtures/hooks/beforeEach-async-error.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

describe('spec 1', function () {
beforeEach(function (done) {
process.nextTick(function () {
throw new Error('before each hook error');
});
});
it('should not run test-1', function () { });
it('should not run test-2', function () { });
});

describe('spec 2', function () {
it('should run test-3', function () { });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

describe('spec 1', function () {
it('should run test-1', function () { });

describe('nested spec 2', function () {
beforeEach(function() {
throw new Error('before each hook error');
});
it('should not run nested test-2', function () { });

describe('deepnested spec 3', function () {
it('should not run deepnested test-3', function () { });
});
});
});
13 changes: 13 additions & 0 deletions test/integration/fixtures/hooks/beforeEach-error.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

describe('spec 1', function () {
beforeEach(function () {
throw new Error('before each hook error');
});
it('should not run test-1', function () { });
it('should not run test-2', function () { });
});

describe('spec 2', function () {
it('should run test-3', function () { });
});

This file was deleted.

19 changes: 0 additions & 19 deletions test/integration/fixtures/hooks/beforeEach-hook-error.fixture.js

This file was deleted.

114 changes: 102 additions & 12 deletions test/integration/hook-err.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,58 @@ describe('hook error handling', function() {
});
});
});

describe('in before each', function() {
it('before each hook error', function(done) {
var fixture = 'hooks/beforeEach-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before each hook error')
.and('to have test count', 3)
.and('to have passed test count', 1)
.and('to have skipped test count', 2)
.and('to have failed test count', 1)
.and('to have passed test', 'should run test-3')
.and(
'to have skipped test order',
'should not run test-1',
'should not run test-2'
)
.and(
'to have failed test',
'"before each" hook for "should not run test-1"'
);
done();
});
});

it('before each hook deepnested error', function(done) {
var fixture = 'hooks/beforeEach-deepnested-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before each hook error')
.and('to have test count', 3)
.and('to have passed test count', 1)
.and('to have skipped test count', 2)
.and('to have failed test count', 1)
.and('to have passed test', 'should run test-1')
.and(
'to have skipped test order',
'should not run nested test-2',
'should not run deepnested test-3'
)
.and(
'to have failed test',
'"before each" hook for "should not run nested test-2"'
);
done();
});
});
});
});

describe('asynchronous hook', function() {
Expand Down Expand Up @@ -166,12 +218,57 @@ describe('hook error handling', function() {
});
});
});
});

describe('before each hook error', function() {
before(run('hooks/beforeEach-hook-error.fixture.js'));
it('should verify results', function() {
expect(lines, 'to equal', ['before', bang + 'test 3']);
describe('in before each', function() {
it('before each hook error', function(done) {
var fixture = 'hooks/beforeEach-async-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before each hook error')
.and('to have test count', 3)
.and('to have passed test count', 1)
.and('to have skipped test count', 2)
.and('to have failed test count', 1)
.and('to have passed test', 'should run test-3')
.and(
'to have skipped test order',
'should not run test-1',
'should not run test-2'
)
.and(
'to have failed test',
'"before each" hook for "should not run test-1"'
);
done();
});
});

it('before each hook deepnested error', function(done) {
var fixture = 'hooks/beforeEach-async-deepnested-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before each hook error')
.and('to have test count', 3)
.and('to have passed test count', 1)
.and('to have skipped test count', 2)
.and('to have failed test count', 1)
.and('to have passed test', 'should run test-1')
.and(
'to have skipped test order',
'should not run nested test-2',
'should not run deepnested test-3'
)
.and(
'to have failed test',
'"before each" hook for "should not run nested test-2"'
);
done();
});
});
});
});

Expand Down Expand Up @@ -271,13 +368,6 @@ describe('hook error handling', function() {
});
});

describe('async - before each hook error', function() {
before(run('hooks/beforeEach-hook-async-error.fixture.js'));
it('should verify results', function() {
expect(lines, 'to equal', ['before', bang + 'test 3']);
});
});

describe('async - after hook error', function() {
before(run('hooks/after-hook-async-error.fixture.js'));
it('should verify results', function() {
Expand Down

0 comments on commit 9bd10b3

Please sign in to comment.