From a63e6d1d672cecae7e09bd00891fa4d24b4d74bb Mon Sep 17 00:00:00 2001 From: juergba Date: Sat, 9 Feb 2019 23:12:21 +0100 Subject: [PATCH] tests after-/Each hooks --- .../pending/skip-sync-after.fixture.js | 37 ++++++++++++++++ .../pending/skip-sync-afterEach.fixture.js | 28 ++++++++++++ test/integration/pending.spec.js | 44 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 test/integration/fixtures/pending/skip-sync-after.fixture.js create mode 100644 test/integration/fixtures/pending/skip-sync-afterEach.fixture.js diff --git a/test/integration/fixtures/pending/skip-sync-after.fixture.js b/test/integration/fixtures/pending/skip-sync-after.fixture.js new file mode 100644 index 0000000000..cae91d42d5 --- /dev/null +++ b/test/integration/fixtures/pending/skip-sync-after.fixture.js @@ -0,0 +1,37 @@ +'use strict'; +var assert = require('assert'); + +describe('skip in after', function () { + it('should run this test-1', function () {}); + + after('should print DeprecationWarning', function () { + this.skip(); + throw new Error('never throws this error'); + }); + after('test should not be marked as pending', function () { + assert(this.currentTest.title === 'should run this test-1'); + assert(this.currentTest.state === 'passed'); + assert(this.currentTest.pending === false); + }); + + + describe('inner suite', function () { + it('should run this test-2', function () {}); + + after('test should not be marked as pending', function () { + assert(this.currentTest.title === 'should run this test-2'); + assert(this.currentTest.state === 'passed'); + assert(this.currentTest.pending === false); + }); + }); +}); + +describe('second suite', function () { + it('should run this test-3', function () {}); + + after('test should not be marked as pending', function () { + assert(this.currentTest.title === 'should run this test-3'); + assert(this.currentTest.state === 'passed'); + assert(this.currentTest.pending === false); + }); +}); diff --git a/test/integration/fixtures/pending/skip-sync-afterEach.fixture.js b/test/integration/fixtures/pending/skip-sync-afterEach.fixture.js new file mode 100644 index 0000000000..b896e70fd5 --- /dev/null +++ b/test/integration/fixtures/pending/skip-sync-afterEach.fixture.js @@ -0,0 +1,28 @@ +'use strict'; +var assert = require('assert'); + +describe('skip in afterEach', function () { + var n = 0; + it('should run this test-1', function () {n = 1;}); + it('should run this test-2', function () {n = 2;}); + + afterEach('should print DeprecationWarning', function () { + this.skip(); + throw new Error('never throws this error'); + }); + afterEach('test should not be marked as pending', function () { + assert(this.currentTest.title === 'should run this test-' + n); + assert(this.currentTest.state === 'passed'); + assert(this.currentTest.pending === false); + }); +}); + +describe('second suite', function () { + it('should run this test-3', function () {}); + + afterEach('test should not be marked as pending', function () { + assert(this.currentTest.title === 'should run this test-3'); + assert(this.currentTest.state === 'passed'); + assert(this.currentTest.pending === false); + }); +}); diff --git a/test/integration/pending.spec.js b/test/integration/pending.spec.js index ea8bd4bf15..aebc6bbeee 100644 --- a/test/integration/pending.spec.js +++ b/test/integration/pending.spec.js @@ -71,6 +71,28 @@ describe('pending', function() { }); }); + describe('in after', function() { + it('should run all tests', function(done) { + runMocha( + 'pending/skip-sync-after.fixture.js', + args, + function(err, res) { + if (err) { + return done(err); + } + expect(res, 'to have passed').and('to satisfy', { + passing: 3, + failing: 0, + pending: 0, + output: expect.it('to contain', "'afterAll' hook is DEPRECATED") + }); + done(); + }, + 'pipe' + ); + }); + }); + describe('in before', function() { it('should skip all suite specs', function(done) { run('pending/skip-sync-before.fixture.js', args, function(err, res) { @@ -145,6 +167,28 @@ describe('pending', function() { }); }); + describe('in afterEach', function() { + it('should run all tests', function(done) { + runMocha( + 'pending/skip-sync-afterEach.fixture.js', + args, + function(err, res) { + if (err) { + return done(err); + } + expect(res, 'to have passed').and('to satisfy', { + passing: 3, + failing: 0, + pending: 0, + output: expect.it('to contain', "'afterEach' hook is DEPRECATED") + }); + done(); + }, + 'pipe' + ); + }); + }); + describe('in beforeEach', function() { it('should skip all suite specs', function(done) { run('pending/skip-sync-beforeEach.fixture.js', args, function(