Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jan 26, 2019
1 parent 3412e7d commit 28671b4
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/integration/fixtures/current-test-title.fixture.js
@@ -0,0 +1,47 @@
'use strict';
var assert = require('assert');

function getTitle(ctx) {
return ctx.currentTest && ctx.currentTest.title;
};

before(function () {
assert.equal(getTitle(this), undefined);
});

describe('suite A', () => {

before(function () {
assert.equal(getTitle(this), undefined);
});

describe('suite B', () => {

it('test1 B', () => {});

describe('suite C', function () {
var lap = 0;

before(function () {
assert.equal(getTitle(this), 'test1 C');
});
beforeEach(function () {
assert.equal(getTitle(this), ++lap === 1 ? 'test1 C' : 'test2 C');
});

it('test1 C', function () {});
it('test2 C', function () {});

afterEach(function () {
assert.equal(getTitle(this), lap === 1 ? 'test1 C' : 'test2 C');
});
after(function () {
assert.equal(getTitle(this), 'test2 C');
});
});
});
});

after(function () {
assert.equal(getTitle(this), undefined);
});
@@ -0,0 +1,13 @@
'use strict';

describe('spec 1', function () {
it('should pass', function () { });
describe('spec 2 nested - this title should be used', function () {
after(function() {
throw new Error('after hook nested error');
});
describe('spec 3 nested', function () {
it('it nested - this title should not be used', function () { });
});
});
});
14 changes: 14 additions & 0 deletions test/integration/fixtures/hooks/after-hook-nested-error.fixture.js
@@ -0,0 +1,14 @@
'use strict';

describe('spec 1', function () {
it('should pass', function () { });
describe('spec nested', function () {
after(function() {
throw new Error('after hook nested error');
});
it('it nested - this title should be used', function () { });
});
describe('spec 2 nested', function () {
it('it nested - not this title', function () { });
});
});
@@ -0,0 +1,13 @@
'use strict';

describe('spec 1', function () {
it('should pass', function () { });
describe('spec 2 nested - this title should be used', function () {
before(function() {
throw new Error('before hook nested error');
});
describe('spec 3 nested', function () {
it('it nested - this title should not be used', function () { });
});
});
});
@@ -0,0 +1,11 @@
'use strict';

describe('spec 1', function () {
it('should pass', function () { });
describe('spec nested', function () {
before(function() {
throw new Error('before hook nested error');
});
it('it nested - this title should be used', function () { });
});
});
@@ -0,0 +1,9 @@
'use strict';

before(function() {
throw new Error('before hook root error');
});

describe('spec 1', function () {
it('should not be called', function () { });
});
101 changes: 101 additions & 0 deletions test/integration/hook-err.spec.js
Expand Up @@ -2,6 +2,7 @@

var helpers = require('./helpers');
var runMocha = helpers.runMocha;
var runMochaJSON = require('./helpers').runMochaJSON;
var splitRegExp = helpers.splitRegExp;
var bang = require('../../lib/reporters/base').symbols.bang;

Expand All @@ -25,6 +26,59 @@ describe('hook error handling', function() {
});
});

describe('before hook root error', function() {
it('should verify results', function(done) {
var fixture = 'hooks/before-hook-root-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before hook root error')
.and('to have failed test', '"before all" hook in "{root}"')
.and('to have passed test count', 0);
done();
});
});
});

describe('before hook nested error', function() {
it('should verify results', function(done) {
var fixture = 'hooks/before-hook-nested-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before hook nested error')
.and(
'to have failed test',
'"before all" hook for "it nested - this title should be used"'
)
.and('to have passed test count', 1)
.and('to have passed test', 'should pass');
done();
});
});
});

describe('before hook deepnested error', function() {
it('should verify results', function(done) {
var fixture = 'hooks/before-hook-deepnested-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'before hook nested error')
.and(
'to have failed test',
'"before all" hook in "spec 2 nested - this title should be used"'
)
.and('to have passed test count', 1)
.and('to have passed test', 'should pass');
done();
});
});
});

describe('before each hook error', function() {
before(run('hooks/beforeEach-hook-error.fixture.js'));
it('should verify results', function() {
Expand All @@ -39,6 +93,53 @@ describe('hook error handling', function() {
});
});

describe('after hook nested error', function() {
it('should verify results', function(done) {
var fixture = 'hooks/after-hook-nested-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'after hook nested error')
.and(
'to have failed test',
'"after all" hook for "it nested - this title should be used"'
)
.and('to have passed test count', 3)
.and(
'to have passed test order',
'should pass',
'it nested - this title should be used',
'it nested - not this title'
);
done();
});
});
});

describe('after hook deepnested error', function() {
it('should verify results', function(done) {
var fixture = 'hooks/after-hook-deepnested-error.fixture.js';
runMochaJSON(fixture, [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'after hook nested error')
.and(
'to have failed test',
'"after all" hook in "spec 2 nested - this title should be used"'
)
.and('to have passed test count', 2)
.and(
'to have passed test order',
'should pass',
'it nested - this title should not be used'
);
done();
});
});
});

describe('after each hook error', function() {
before(run('hooks/afterEach-hook-error.fixture.js'));
it('should verify results', function() {
Expand Down
13 changes: 13 additions & 0 deletions test/integration/hooks.spec.js
Expand Up @@ -2,6 +2,7 @@

var assert = require('assert');
var runMocha = require('./helpers').runMocha;
var runMochaJSON = require('./helpers').runMochaJSON;
var splitRegExp = require('./helpers').splitRegExp;
var args = ['--reporter', 'dot'];

Expand Down Expand Up @@ -49,4 +50,16 @@ describe('hooks', function() {
done();
});
});

it('current test title of all hooks', function(done) {
runMochaJSON('current-test-title.fixture.js', [], function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have passed')
.and('to have passed test count', 3)
.and('to have passed test order', 'test1 B', 'test1 C', 'test2 C');
done();
});
});
});

0 comments on commit 28671b4

Please sign in to comment.