Skip to content

Commit

Permalink
add pending state to xit() and xdescribe()
Browse files Browse the repository at this point in the history
  • Loading branch information
bionicbrian authored and tj committed Jul 26, 2012
1 parent d941f46 commit 984d64e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
29 changes: 23 additions & 6 deletions lib/interfaces/bdd.js
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -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);
};
});
};
6 changes: 6 additions & 0 deletions lib/suite.js
Expand Up @@ -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;
Expand All @@ -49,6 +50,7 @@ function Suite(title, ctx) {
this.ctx = ctx;
this.suites = [];
this.tests = [];
this.pending = false;
this._beforeEach = [];
this._beforeAll = [];
this._afterEach = [];
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
15 changes: 12 additions & 3 deletions mocha.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
};
});
Expand Down

0 comments on commit 984d64e

Please sign in to comment.