Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Changed: pass Test object to beforEach/afterEach

Tj Holowaychuk04cd1a566b6d
diff --git a/lib/runner.js b/lib/runner.js
index 78e443b9..4cdc08aa 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -64,7 +64,7 @@ Runner.prototype.runTests = function(suite, fn){
self.emit('test', test);
// run any befores first
suite.setup.forEach(function(fn){
- fn();
+ fn(test);
});
// run the test
try {
@@ -96,7 +96,7 @@ Runner.prototype.runTests = function(suite, fn){
self.emit('test end', test);
// teardown hook
suite.tearDown.forEach(function(fn){
- fn();
+ fn(test);
});
run(tests.shift());
}
diff --git a/test/unit/basic.js b/test/unit/basic.js
deleted file mode 100644
index f0eda8e0..00000000
--- a/test/unit/basic.js
+++ /dev/null
@@ -1,15 +0,0 @@
-
-describe('serial', function(){
- describe('before', function(){
- var calls = [];
-
- before(function(test){
- calls.push(test.fullTitle());
- });
-
- it('one', function(){
- console.log(calls);
- });
-
- });
-});
\ No newline at end of file
diff --git a/test/unit/beforeEach.serial.js b/test/unit/beforeEach.serial.js
new file mode 100644
index 00000000..ffac3037
--- /dev/null
+++ b/test/unit/beforeEach.serial.js
@@ -0,0 +1,27 @@
+
+describe('serial', function(){
+ describe('beforeEach()', function(){
+ var calls = [];
+
+ beforeEach(function(test){
+ calls.push(test.fullTitle());
+ });
+
+ it('one', function(){
+ calls.should.eql(['serial beforeEach() one']);
+ });
+
+ it('two', function(){
+ calls.should.eql([
+ 'serial beforeEach() one'
+ , 'serial beforeEach() two']);
+ });
+
+ it('three', function(){
+ calls.should.eql([
+ 'serial beforeEach() one'
+ , 'serial beforeEach() two'
+ , 'serial beforeEach() three']);
+ });
+ });
+});
\ No newline at end of file