Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Added suiteSetup and suiteTeardown to allow setup and teardown for the whole tdd suite#

David Hendersonff011726ca04
diff --git a/lib/interfaces/tdd.js b/lib/interfaces/tdd.js
index a3f35c4b..a1115c8b 100644
--- a/lib/interfaces/tdd.js
+++ b/lib/interfaces/tdd.js
@@ -8,9 +8,14 @@ var Suite = require('../suite')
/**
* TDD-style interface:
- *
+ *
* suite('Array', function(){
* suite('#indexOf()', function(){
+ *
+ * suiteSetup(function(){
+ *
+ * });
+ *
* test('should return -1 when not present', function(){
*
* });
@@ -18,9 +23,13 @@ var Suite = require('../suite')
* test('should return the index when present', function(){
*
* });
+ *
+ * suiteTeardown(function(){
+ *
+ * });
* });
* });
- *
+ *
*/
module.exports = function(suite){
@@ -37,19 +46,38 @@ module.exports = function(suite){
};
/**
- * Execute before each test case.
+ * Execute after each test case.
*/
context.teardown = function(fn){
suites[0].afterEach(fn);
};
+ /**
+ * Execute before the suite.
+ */
+
+ context.suiteSetup = function(fn){
+ suites[0].beforeAll(fn);
+ };
+
+ /**
+ * Execute after the suite.
+ */
+
+ context.suiteTeardown = function(fn){
+ suites[0].afterAll(fn);
+ };
+
+
+
+
/**
* Describe a "suite" with the given `title`
* and callback `fn` containing nested suites
* and/or tests.
*/
-
+
context.suite = function(title, fn){
var suite = Suite.create(suites[0], title);
suites.unshift(suite);
diff --git a/test/interfaces/tdd.js b/test/interfaces/tdd.js
index c6f23080..d63f500b 100644
--- a/test/interfaces/tdd.js
+++ b/test/interfaces/tdd.js
@@ -1,15 +1,29 @@
suite('Array', function(){
suite('#indexOf()', function(){
+ var initialValue = 32;
+
+ suiteSetup(function(done){
+ initialValue.should.eql(32);
+ initialValue = 42;
+ done();
+ });
+
test('should return -1 when the value is not present', function(){
+ initialValue.should.eql(42);
[1,2,3].indexOf(5).should.equal(-1);
[1,2,3].indexOf(0).should.equal(-1);
})
test('should return the correct index when the value is present', function(){
+ initialValue.should.eql(42);
[1,2,3].indexOf(1).should.equal(0);
[1,2,3].indexOf(2).should.equal(1);
[1,2,3].indexOf(3).should.equal(2);
})
+ suiteTeardown(function(done){
+ initialValue.should.eql(42);
+ done();
+ });
})
})