Sha256: c9c78671696c6165f8d7cb2e3c1e3ec2226d803f0689616c0e928be44a70a922

Contents?: true

Size: 1.64 KB

Versions: 13

Compression:

Stored size: 1.64 KB

Contents

/**
 * Module dependencies.
 */

var Suite = require('../suite')
  , Test = require('../test');

/**
 * QUnit-style interface:
 * 
 *     suite('Array');
 *     
 *     test('#length', function(){
 *       var arr = [1,2,3];
 *       ok(arr.length == 3);
 *     });
 *     
 *     test('#indexOf()', function(){
 *       var arr = [1,2,3];
 *       ok(arr.indexOf(1) == 0);
 *       ok(arr.indexOf(2) == 1);
 *       ok(arr.indexOf(3) == 2);
 *     });
 *     
 *     suite('String');
 *     
 *     test('#length', function(){
 *       ok('foo'.length == 3);
 *     });
 * 
 */

module.exports = function(suite){
  var suites = [suite];

  suite.on('pre-require', function(context){

    /**
     * Execute before running tests.
     */

    context.before = function(fn){
      suites[0].beforeAll(fn);
    };

    /**
     * Execute after running tests.
     */

    context.after = function(fn){
      suites[0].afterAll(fn);
    };

    /**
     * Execute before each test case.
     */

    context.beforeEach = function(fn){
      suites[0].beforeEach(fn);
    };

    /**
     * Execute after each test case.
     */

    context.afterEach = function(fn){
      suites[0].afterEach(fn);
    };

    /**
     * Describe a "suite" with the given `title`.
     */
  
    context.suite = function(title){
      if (suites.length > 1) suites.shift();
      var suite = Suite.create(suites[0], title);
      suites.unshift(suite);
    };

    /**
     * Describe a specification or test-case
     * with the given `title` and callback `fn`
     * acting as a thunk.
     */

    context.test = function(title, fn){
      suites[0].addTest(new Test(title, fn));
    };
  });
};

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
stylus-source-0.31.0 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.30.1 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.30.0 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.29.0 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.28.2 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.28.1 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.28.0 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.27.2 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.27.1 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.27.0 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.26.1 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.26.0 vendor/node_modules/mocha/lib/interfaces/qunit.js
stylus-source-0.25.0 vendor/node_modules/mocha/lib/interfaces/qunit.js