Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
krisb opened this issue Mar 30, 2014 · 1 comment
Assignees
Labels
bug Bug or defect
Milestone

Comments

@krisb
Copy link
Contributor

krisb commented Mar 30, 2014

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.

@hueniverse hueniverse added the bug label Mar 30, 2014
@hueniverse hueniverse added this to the 3.0.0 milestone Mar 30, 2014
@hueniverse hueniverse self-assigned this Mar 30, 2014
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants