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

Failing async before() (bdd) or suiteSetup() (tdd) reports against the previous suite #119

Closed
dhendo opened this issue Dec 6, 2011 · 7 comments

Comments

@dhendo
Copy link
Contributor

dhendo commented Dec 6, 2011

If you have an asynchronous section in a before() or suiteSetup() that fails, the error is reported against the previous test suite:

TDD ui case

var should = require('should');

testSetup = function(done) {
    setTimeout(function() {
        // Either a failed assertion
        should.exist(somethingthatdoesntexist);
        // Or a thrown error
        //throw new Error("Something went wrong here... and ");
    }, 10);
};

suite('The First test suite', function() {
    test('has one test', function(done) {
        done();
    });

    test('has a second test', function(done) {
        done();
    });

});

// Now fail inside an async section in the test setup
suite('The Second suite', function() {
    suiteSetup(testSetup);
    test('has one test', function(done) {
        done();
    });
});

Output

  The First test suite
    ? has one test  
    ? has a second test  

  The Second suite
    0) has a second test

  ? 1 of 3 tests failed:

  0) The First test suite has a second test:
     ReferenceError: somethingthatdoesntexist is not defined

BDD ui test case

var should = require('should');

testSetup = function(done) {
    setTimeout(function() {
        // Either a failed assertion
        should.exist(somethingthatdoesntexist);
        // Or a thrown error
        //throw new Error("Something went wronghere... and ");
    }, 10);
};

describe('The First test suite', function() {
    describe('has one test', function() {
        it('is great', function(done) {
            done();
        });
    });

    describe('has a second test', function() {
        it('is great', function(done) {
            done();
        });
    });

});


// Now fail inside an async section in the test setup
describe('The Second suite', function() {
    before(testSetup);
    describe('has one test', function() {
        it('is great', function(done) {
            done();
        });
    });
});

Expected results

" 0) The First test suite has a second test:
     ReferenceError: somethingthatdoesntexist is not defined"

This is incorrect - and should report that the failure was in the beforeAll hook:

  0) The Second suite "before all" hook:
     ReferenceError: somethingthatdoesntexist is not defined

As it does if the error is thrown outside the setTimeout function.

@tj
Copy link
Contributor

tj commented Dec 7, 2011

appears fine to me:

describe('first', function(){
  it('should something', function(done){
    done()
  })
})

describe('second', function(){
  before(function(done){
    process.nextTick(function(){
      throw new Error('failed')
    });
  })

  it('should do something', function(done){
    done()
  })
})

outputs:


..

  ✖ 1 of 2 tests failed:

  0) second "before all" hook:
     Error: failed
      at Array.0 (/Users/tj/Projects/mocha/test.js:11:13)
      at EventEmitter._tickCallback (node.js:192:40)

@tj
Copy link
Contributor

tj commented Dec 7, 2011

did i miss something?

@dhendo
Copy link
Contributor Author

dhendo commented Dec 8, 2011

Your code sample fails for me:

  ..

  ✖ 1 of 2 tests failed:

  0) first should something:
     Error: failed
      at Array.0 (/home/davidh/dev/TriggeredMessagingV1/node/mochatest/test/test.js:10:13)
      at EventEmitter._tickCallback (node.js:192:40)

Using mocha 0.3.2, node 0.6.5 on Ubuntu

@tj
Copy link
Contributor

tj commented Dec 8, 2011

which version of mocha?

@dhendo
Copy link
Contributor Author

dhendo commented Dec 8, 2011

0.3.2

@tj
Copy link
Contributor

tj commented Dec 8, 2011

weiiird... very weird, I get the expected results for node 0.4.x and 0.6.x

@dhendo
Copy link
Contributor Author

dhendo commented Dec 8, 2011

Very strange. I've managed to try it on a few more machines, and it seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants