I have such a mocha test:
describe 'sabah', → beforeEach → @sabahStrategy = _.filter(@strats, { name: 'sabah2' })[0] .strat it 'article list should be populated', (done) → @timeout 10000 strat = new @sabahStrategy() articles = strat.getArticleStream('barlas') articles.take(2).toArray( (result)→ _.each(result, (articleList) →
The problem is that whenever I do assert(false) , the test hangs before the timeout instead of giving an assertion error, why?
Edit:
For example, if I have these two tests
it 'assert false', (done) → assert(false) done() it 'article link stream should be populated', (done) → @timeout 20000 articles = @sabahStrategy.articleLinkStream('barlas') articles.pull((err, result)→ console.log('here') assert(false) console.log('after') assert(!err) assert(result.length > 1); _.each(result, (articleList) → assert(articleList.link) ) done() )
The first one gives an assertion error, as expected, the second one, logs here and hangs on assert(false) , so after never logged. This is because articles is a stream and the statement is in the pull callback, this is from the highland.js API .
Decided to Change :
So, according to Paul, I fixed the problem with this code:
it 'article stream should be populated', (done) → @timeout 30000 articles = @sabahStrategy.articleStream('barlas') articles.pull((err, result) → try
Edit2
I created a simplified version of the problem:
h = require('highland') Q = require('q') describe 'testasynchigh', → beforeEach → @deferred = Q.defer() setTimeout((→ @deferred.resolve(1) ).bind(this), 50) it 'should throw', (done) → s = h(@deferred.promise); s.pull((err, result) → console.log result assert false done() )
I see that your version really works @Louis, but if you include promises in the mix, mocha will not be able to deal with this problem, so it will hang in this example. Also try commenting on assert false and see how it goes.
So, Louis, I hope I have drawn your attention, could you explain the problem, and try catch looks ugly, and I hope you find a reasonable solution to this.