Permalink
Browse files

add pending state to xit() and xdescribe()

  • Loading branch information...
1 parent d941f46 commit 984d64e77aa98a3a05a5562559b60e12d20ec867 @bionicbrian bionicbrian committed with tj Jul 26, 2012
Showing with 41 additions and 9 deletions.
  1. +23 −6 lib/interfaces/bdd.js
  2. +6 −0 lib/suite.js
  3. +12 −3 mocha.js
View
@@ -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.
*/
@@ -66,6 +61,18 @@ module.exports = function(suite){
};
/**
+ * 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
* and/or tests.
@@ -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);
};
});
};
View
@@ -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());
View
@@ -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));
};
});

0 comments on commit 984d64e

Please sign in to comment.