Skip to content

When test fails in async callback it aborts other tests #94

Closed

Description

describe('mocha tests', function() {
    it('should go to the next test when it fails (outside callback)', function(done){
        throw new Error('the other test should still run');
        done();
    });

    it('should go to the next test when it fails (inside callback)', function(done) {

        setTimeout(function() {
            throw new Error('the other test should still run');
            done();
        }, 0);
    });

    it('should get to this test', function(done) {
        done();
    });
});

I expect that it should run all the tests and report 2 failures and 1 success. Instead I get this (only 2 out of 3 tests were run):

mocha ./test/test.test.js

  ..

  ✖ 2 of 3 tests failed:

  0) mocha tests should go to the next test when it fails (outside callback):
     Error: the other test should still run

  at Test.fn (/Users/me/mochatest/test/test.test.js:3:19)
      at Test.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:103:12)
      at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:244:10)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:290:12
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:172:14)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:181:7
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:133:23)
      at Array.0 (/usr/local/lib/node_modules/mocha/lib/runner.js:149:5)
      at EventEmitter._tickCallback (node.js:192:40)

  1) mocha tests should go to the next test when it fails:
     Error: the other test should still run

  at Timer.ontimeout (/Users/me/mochatest/test/test.test.js:10:23)

This is the same if I'm running multiple files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions