Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Feb 19, 2019
1 parent 3fa7fd0 commit e285f52
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
@@ -0,0 +1,26 @@
'use strict';

describe('skip conditionally in beforeEach', function () {
var n = 1;
beforeEach(function () {
if (n !== 2) {
this.skip();
}
});

it('should never run this test-1', function () {
throw new Error('never run this test');
});
it('should run this test-2', function () {});

describe('inner suite', function() {
it('should never run this test-3', function () {
throw new Error('never run this test');
});
});

afterEach(function() { n++; });
after(function() {
throw new Error('should throw this error');
});
});
21 changes: 18 additions & 3 deletions test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js
@@ -1,15 +1,30 @@
'use strict';
var assert = require('assert');

describe('skip in beforeEach', function () {
var runOrder = [];
beforeEach(function () {
runOrder.push('beforeEach');
this.skip();
});

it('should never run this test', function () {
it('should never run this test-1', function () {
throw new Error('never run this test');
});

it('should never run this test', function () {
it('should never run this test-2', function () {
throw new Error('never run this test');
});

afterEach(function() {
runOrder.push('afterEach');
});
after(function() {
runOrder.push('after');
assert.deepStrictEqual(runOrder, [
'beforeEach', 'afterEach',
'beforeEach', 'afterEach',
'after'
]);
throw new Error('should throw this error');
});
});
41 changes: 31 additions & 10 deletions test/integration/pending.spec.js
Expand Up @@ -147,18 +147,39 @@ describe('pending', function() {

describe('in beforeEach', function() {
it('should skip all suite specs', function(done) {
run('pending/skip-sync-beforeEach.fixture.js', args, function(
err,
res
) {
var fixture = 'pending/skip-sync-beforeEach.fixture.js';
run(fixture, args, function(err, res) {
if (err) {
done(err);
return;
return done(err);
}
assert.strictEqual(res.stats.pending, 2);
assert.strictEqual(res.stats.passes, 0);
assert.strictEqual(res.stats.failures, 0);
assert.strictEqual(res.code, 0);
expect(res, 'to have failed with error', 'should throw this error')
.and('to have failed test count', 1)
.and('to have pending test count', 2)
.and(
'to have pending test order',
'should never run this test-1',
'should never run this test-2'
)
.and('to have passed test count', 0);
done();
});
});
it('should skip only two suite specs', function(done) {
var fixture = 'pending/skip-sync-beforeEach-cond.fixture.js';
run(fixture, args, function(err, res) {
if (err) {
return done(err);
}
expect(res, 'to have failed with error', 'should throw this error')
.and('to have failed test count', 1)
.and('to have pending test count', 2)
.and(
'to have pending test order',
'should never run this test-1',
'should never run this test-3'
)
.and('to have passed test count', 1)
.and('to have passed test', 'should run this test-2');
done();
});
});
Expand Down

0 comments on commit e285f52

Please sign in to comment.