From 4c0df7014f31b91a2cd05312437e3e0b56af6a59 Mon Sep 17 00:00:00 2001 From: Ahmad Bamieh Date: Tue, 12 Dec 2017 08:54:13 +0200 Subject: [PATCH] return the created test in `xit` for bdd interface; closes #3142 (#3143) * Fixes https://github.com/mochajs/mocha/issues/3142 * added test cases suggested by @boneskull * fixed miswording * attempt to fix bizarre AppVeyor problem by way of npm upgrade --- appveyor.yml | 1 + lib/interfaces/bdd.js | 2 +- .../pending/skip-shorthand.fixture.js | 7 ++++++ test/integration/pending.spec.js | 13 ++++++++++ test/interfaces/bdd.spec.js | 24 +++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/pending/skip-shorthand.fixture.js diff --git a/appveyor.yml b/appveyor.yml index 2fe1c21c65..28da3062f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,6 +9,7 @@ install: - set CI=true - set PATH=%APPDATA%\npm;c:\MinGW\bin;%PATH% - set PHANTOMJS_CDNURL=https://cnpmjs.org/downloads + - npm install -g npm - npm install - copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe matrix: diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 33efc169a2..7a54375a94 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -102,7 +102,7 @@ module.exports = function (suite) { */ context.xit = context.xspecify = context.it.skip = function (title) { - context.it(title); + return context.it(title); }; /** diff --git a/test/integration/fixtures/pending/skip-shorthand.fixture.js b/test/integration/fixtures/pending/skip-shorthand.fixture.js new file mode 100644 index 0000000000..399dc48a65 --- /dev/null +++ b/test/integration/fixtures/pending/skip-shorthand.fixture.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('pending shorthand', function () { + xit('pending spec', function () {}).timeout(0); + xspecify('pending spec', function () {}).timeout(0); + it.skip('pending spec', function () {}).timeout(0); +}); diff --git a/test/integration/pending.spec.js b/test/integration/pending.spec.js index f5a400f089..30cf61ceb2 100644 --- a/test/integration/pending.spec.js +++ b/test/integration/pending.spec.js @@ -19,6 +19,19 @@ describe('pending', function () { done(); }); }); + it('should return the test object when used via shorthand methods', function (done) { + run('pending/skip-shorthand.fixture.js', args, function (err, res) { + if (err) { + done(err); + return; + } + assert.equal(res.stats.pending, 3); + assert.equal(res.stats.passes, 0); + assert.equal(res.stats.failures, 0); + assert.equal(res.code, 0); + done(); + }); + }); }); describe('synchronous skip()', function () { diff --git a/test/interfaces/bdd.spec.js b/test/interfaces/bdd.spec.js index 2289c12497..14365dc39a 100644 --- a/test/interfaces/bdd.spec.js +++ b/test/interfaces/bdd.spec.js @@ -40,3 +40,27 @@ describe('pending suite', function () { }); }); }); + +describe('pending tests', function () { + it.skip('should not run', function () { + expect(1 + 1).to.equal(3); + }); +}); + +describe('setting timeout by appending it to test', function () { + var runningTest = it('enables users to call timeout on active tests', function () { + expect(1 + 1).to.equal(2); + }).timeout(1003); + + var skippedTest = xit('enables users to call timeout on pending tests', function () { + expect(1 + 1).to.equal(3); + }).timeout(1002); + + it('sets timeout on pending tests', function () { + expect(skippedTest._timeout).to.equal(1002); + }); + + it('sets timeout on running tests', function () { + expect(runningTest._timeout).to.equal(1003); + }); +});