visionmedia/mocha — Issue #218: suppresses thrown errors
Author: kidlingo
Created: 2012-01-17 03:04:00+00:00
State: open

Code that I'm testing throws an error. This error does not appear in the test output, making it difficult to determine why the test failed. It would be much more helpful if mocha always listed the stacktrace of any errors thrown during a test.

This test (along with others):

it ("creates the top-level object", function () {
var result = fillObjectTree.fillObjectTree (dataSet1, example);
result.id.should.equal (1001);
});

Produces:

✖ 17 of 58 tests failed:

0) fill_object_tree createMap fillObjectTree creates the top-level object:

1) fill_object_tree createMap fillObjectTree creates the measurableQuantity:

Note the lack of detail under the failed test.

If I wrap the test code in a try/catch, it outputs the error in the console output:

it ("creates the top-level object", function () {
try {
var result = fillObjectTree.fillObjectTree (dataSet1, example);
} catch (e) {
log.error(e);
}
result.id.should.equal (1001);
});

ERROR The provided object to fill (object) does not match the example object map's type (array) at path [.measurableQuantity.unitConversions], Error
at Object.error (/Users/jacobmiles/projects/sefaira-svn/trunk/node_app/lib/log.js:23:64)
at Test.fn (/Users/jacobmiles/projects/sefaira-svn/trunk/node_app/lib/fill_object_tree.spec.js:346:11)
at Test.run (/opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runnable.js:153:3

And provides more output under that test result:

0) fill_object_tree createMap fillObjectTree creates the top-level object:
TypeError: Cannot read property 'id' of undefined
at Test.fn (/Users/jacobmiles/projects/sefaira-svn/trunk/node_app/lib/fill_object_tree.spec.js:348:9)
at Test.run (/opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runnable.js:153:32)
at Runner.runTest (/opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runner.js:271:10)
at /opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runner.js:315:12
at next (/opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runner.js:199:14)
at /opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runner.js:208:7
at next (/opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runner.js:157:23)
at Array. (/opt/local/lib/node/.npm/mocha/0.10.0/package/lib/runner.js:176:5)
at EventEmitter._tickCallback (node.js:126:26)