Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

add pending state to xit() and xdescribe()

Brian Moore984d64e77aa9
diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js
index e0285dac..b5a6b93d 100644
--- a/lib/interfaces/bdd.js
+++ b/lib/interfaces/bdd.js
@@ -28,11 +28,6 @@ module.exports = function(suite){
suite.on('pre-require', function(context){
- // noop variants
-
- context.xdescribe = function(){};
- context.xit = function(){};
-
/**
* Execute before running tests.
*/
@@ -65,6 +60,18 @@ module.exports = function(suite){
suites[0].afterEach(fn);
};
+ /**
+ * Pending describe.
+ */
+
+ context.xdescribe = context.xcontext = function(title, fn){
+ var suite = Suite.create(suites[0], title);
+ suite.pending = true;
+ suites.unshift(suite);
+ fn();
+ suites.shift();
+ };
+
/**
* Describe a "suite" with the given `title`
* and callback `fn` containing nested suites
@@ -85,7 +92,17 @@ module.exports = function(suite){
*/
context.it = context.specify = function(title, fn){
- suites[0].addTest(new Test(title, fn));
+ var suite = suites[0];
+ if (suite.pending) var fn = null;
+ suite.addTest(new Test(title, fn));
+ };
+
+ /**
+ * Pending test case.
+ */
+
+ context.xit = context.xspecify = function(title){
+ context.it(title);
};
});
};
diff --git a/lib/suite.js b/lib/suite.js
index 31c0a1ae..d6ae40ef 100644
--- a/lib/suite.js
+++ b/lib/suite.js
@@ -30,6 +30,7 @@ exports = module.exports = Suite;
exports.create = function(parent, title){
var suite = new Suite(title, parent.ctx);
suite.parent = parent;
+ if (parent.pending) suite.pending = true;
title = suite.fullTitle();
parent.addSuite(suite);
return suite;
@@ -49,6 +50,7 @@ function Suite(title, ctx) {
this.ctx = ctx;
this.suites = [];
this.tests = [];
+ this.pending = false;
this._beforeEach = [];
this._beforeAll = [];
this._afterEach = [];
@@ -120,6 +122,7 @@ Suite.prototype.bail = function(bail){
*/
Suite.prototype.beforeAll = function(fn){
+ if (this.pending) return this;
var hook = new Hook('"before all" hook', fn);
hook.parent = this;
hook.timeout(this.timeout());
@@ -138,6 +141,7 @@ Suite.prototype.beforeAll = function(fn){
*/
Suite.prototype.afterAll = function(fn){
+ if (this.pending) return this;
var hook = new Hook('"after all" hook', fn);
hook.parent = this;
hook.timeout(this.timeout());
@@ -156,6 +160,7 @@ Suite.prototype.afterAll = function(fn){
*/
Suite.prototype.beforeEach = function(fn){
+ if (this.pending) return this;
var hook = new Hook('"before each" hook', fn);
hook.parent = this;
hook.timeout(this.timeout());
@@ -174,6 +179,7 @@ Suite.prototype.beforeEach = function(fn){
*/
Suite.prototype.afterEach = function(fn){
+ if (this.pending) return this;
var hook = new Hook('"after each" hook', fn);
hook.parent = this;
hook.timeout(this.timeout());
diff --git a/mocha.js b/mocha.js
index 91a66d70..8b13503c 100644
--- a/mocha.js
+++ b/mocha.js
@@ -537,10 +537,18 @@ module.exports = function(suite){
suite.on('pre-require', function(context){
- // noop variants
+ // pending variants
- context.xdescribe = function(){};
- context.xit = function(){};
+ context.xdescribe = function(title, fn){
+ var suite = Suite.create(suites[0], title);
+ suite.pending = true;
+ suites.unshift(suite);
+ fn();
+ suites.shift();
+ };
+ context.xit = function(title){
+ context.it(title);
+ };
/**
* Execute before running tests.
@@ -594,6 +602,7 @@ module.exports = function(suite){
*/
context.it = context.specify = function(title, fn){
+ if (suites[0].pending) var fn = undefined;
suites[0].addTest(new Test(title, fn));
};
});