From f23a057f5137007c3e00b8b183f7f44213d3bf32 Mon Sep 17 00:00:00 2001 From: juergba Date: Tue, 19 Feb 2019 10:59:23 +0100 Subject: [PATCH] test --- .../pending/skip-async-beforeEach.fixture.js | 17 +++++++ .../skip-sync-beforeEach-cond.fixture.js | 28 +++++++++++ .../pending/skip-sync-beforeEach.fixture.js | 21 +++++++-- test/integration/pending.spec.js | 47 ++++++++++++++----- 4 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 test/integration/fixtures/pending/skip-sync-beforeEach-cond.fixture.js diff --git a/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js b/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js index a450e44bdd..a4dec86d42 100644 --- a/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js +++ b/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js @@ -1,7 +1,10 @@ 'use strict'; +var assert = require('assert'); describe('skip in beforeEach', function () { + var runOrder = []; beforeEach(function (done) { + runOrder.push('beforeEach'); var self = this; setTimeout(function () { self.skip(); // done() is not required @@ -17,4 +20,18 @@ describe('skip in beforeEach', function () { it('should skip this test-3', 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', + 'beforeEach', 'afterEach', + 'after' + ]); + throw new Error('should throw this error'); + }); }); diff --git a/test/integration/fixtures/pending/skip-sync-beforeEach-cond.fixture.js b/test/integration/fixtures/pending/skip-sync-beforeEach-cond.fixture.js new file mode 100644 index 0000000000..f878631de2 --- /dev/null +++ b/test/integration/fixtures/pending/skip-sync-beforeEach-cond.fixture.js @@ -0,0 +1,28 @@ +'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() { + if (n === 4) { + throw new Error('should throw this error'); + } + }); +}); diff --git a/test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js b/test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js index 2312265613..b936a447b0 100644 --- a/test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js +++ b/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'); + }); }); diff --git a/test/integration/pending.spec.js b/test/integration/pending.spec.js index 7b96d36001..d0a92b6113 100644 --- a/test/integration/pending.spec.js +++ b/test/integration/pending.spec.js @@ -169,18 +169,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(); }); }); @@ -285,8 +306,8 @@ describe('pending', function() { if (err) { return done(err); } - expect(res, 'to have passed') - .and('to have passed test count', 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', 3) .and( 'to have pending test order', @@ -294,7 +315,7 @@ describe('pending', function() { 'should skip this test-2', 'should skip this test-3' ) - .and('to have failed test count', 0); + .and('to have passed test count', 0); done(); }); });