Skip to content

armgit / mocha

Public Imported from GitHub
0

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

setup for tdd style

James Carr64d67386a2d0
diff --git a/lib/interfaces/tdd.js b/lib/interfaces/tdd.js
index 1e05a814..0f43d18d 100644
--- a/lib/interfaces/tdd.js
+++ b/lib/interfaces/tdd.js
@@ -27,7 +27,14 @@ module.exports = function(suite){
var suites = [suite];
suite.on('pre-require', function(context, file){
+ /**
+ * Defines a setup function to execute before
+ * the execution of each test.
+ */
+ context.setup = function(fn){
+ suites[0].addSetup(fn);
+ }
/**
* Describe a "suite" with the given `title`
* and callback `fn` containing nested suites
@@ -52,4 +59,4 @@ module.exports = function(suite){
suites[0].addTest(new Test(title, fn));
};
});
-};
\ No newline at end of file
+};
diff --git a/lib/runner.js b/lib/runner.js
index 8810ac76..ff8b7d2f 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -52,6 +52,13 @@ Runner.prototype.runTests = function(suite, fn){
var self = this
, tests = suite.tests;
+/**
+ * Add a test `suite`.
+ *
+ * @param {Suite} suite
+ * @return {Suite} for chaining
+ * @api private
+ */
function run(test) {
if (!test) return fn();
self.emit('test', test);
diff --git a/test/setup-test.js b/test/setup-test.js
deleted file mode 100644
index 2f14fc3c..00000000
--- a/test/setup-test.js
+++ /dev/null
@@ -1,13 +0,0 @@
-var assert = require('assert');
-
-describe("Setup", function(){
- var x = 0;
- before(function(){
- x = 1;
- });
- it("should have executed before", function(){
- assert.equal(x, 1);
- })
-
-});
-