unit testing - Make mocha tests show the actual error -


one of things find frustrating mocha when tests fail, don't give actual error message of failing line, instead, end error: timeout of 2000ms exceeded. ensure done() callback being called in test.

take test example:

describe("mytest", function() {     it("should return valid json.", function(done) {         api.mycall("valid value").then(function(result) {             console.log(result);             var resultobj = json.parse(result);             assert.isfalse(resultobj.hasownproperty("error"), "result has error");             done();         });     }); }); 

the output is:

  mytest {"error":null,"status":403}     1) should return valid json.     0 passing (2s)   1 failing    1) mytest should return valid json.:      error: timeout of 2000ms exceeded. ensure done() callback being called in test. 

the assert.isfalse failing, message should displayed ("result has error") isn't displayed. in fact, processing seems stop right there because done() never called. take line out , test passes because done() called.

so, missing? why mocha tests behave way? actual test library i'm using is:

var assert = require("chai").assert;  

does know i'm doing wrong or why behaves way?

it looks api using promises. before trying else, suggest checking documentation of api says promises , how deal unhandled exceptions because may happening here. promise implementations require call .done() @ end of call chain ensure uncaught exceptions going processed. require global promise setting configured. bluebird documentation gives discussion of issues.

mocha capable of handling uncaught exceptions in run-of-the-mill code:

var chai = require("chai"); var assert = chai.assert; chai.config.includestack = true;  describe("foo", function() {     it("let exception caught mocha", function(done) {         settimeout(function () {             assert.isfalse(true, "foo");             done();         }, 1000);     }); }); 

this result in output:

  foo     1) let exception caught mocha     0 passing (1s)   1 failing    1) foo let exception caught mocha:      uncaught assertionerror: foo: expected true false       @ assertion.<anonymous> (/tmp/t7/node_modules/chai/lib/chai/core/assertions.js:286:10)       @ assertion.object.defineproperty.get (/tmp/t7/node_modules/chai/lib/chai/utils/addproperty.js:35:29)       @ function.assert.isfalse (/tmp/t7/node_modules/chai/lib/chai/interface/assert.js:297:31)       @ null._ontimeout (/tmp/t7/test.js:8:20)       @ timer.listontimeout (timers.js:119:15) 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -