# before/beforeEach/afterEach/after not run in correct order when using nested experiments #66

Closed
opened this issue Mar 30, 2014 · 0 comments
Closed

# before/beforeEach/afterEach/after not run in correct order when using nested experiments#66

opened this issue Mar 30, 2014 · 0 comments
Assignees
Labels
Milestone

 Consider the following test: ```var Lab = require('lab'); Lab.experiment('calculator', function () { Lab.before(function (done) { console.log('called: before'); done(); }); Lab.beforeEach(function (done) { console.log('called: beforeEach'); done(); }); Lab.afterEach(function (done) { console.log('called: afterEach'); done(); }); Lab.after(function (done) { console.log('called: after'); done(); }); Lab.test('returns true when zero', function (done) { console.log('called: test'); Lab.expect(0).to.equal(0); done(); }); Lab.experiment('addition', function () { Lab.test('returns true when 1 + 1 equals 2', function (done) { console.log('called: test'); Lab.expect(1+1).to.equal(2); done(); }); }); Lab.experiment('subtract', function () { Lab.test('returns true when 1 - 1 equals 0', function (done) { console.log('called: test'); Lab.expect(1-1).to.equal(0); done(); }); }); });``` Run with tap (`lab examples/nested_experiments.js -r tap`) and you get the following output: ``````1..3 called: before called: beforeEach called: test ok 1 calculator returns true when zero called: afterEach called: after called: test ok 2 calculator addition returns true when 1 + 1 equals 2 called: test ok 3 calculator subtract returns true when 1 - 1 equals 0 # tests 3 # pass 3 # fail 0 `````` expected output should be: ``````1..3 called: before called: beforeEach called: test ok 1 calculator returns true when zero called: afterEach called: beforeEach called: test ok 2 calculator addition returns true when 1 + 1 equals 2 called: afterEach called: beforeEach called: test ok 3 calculator subtract returns true when 1 - 1 equals 0 called: afterEach called: after # tests 3 # pass 3 # fail 0 `````` Note: I've used tap for the simplistic output - its not a symptom of that formatter, more so structure of the experiments built in index.js.
closed this in ``` 0309c10 ``` Mar 30, 2014