I have this kind of 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) →
// I make the assertions here
// assert(false)
assert(articleList.length > 1)
)
done()
)
The problem is, whenever I do assert(false)
, the test hangs until 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 the assertion error as expected, the second one, logs here
, and hangs at assert(false)
so after
is never logged. It has something to do with articles
being a stream and the assertion is within a pull
callback, this is from the highland.js API.
Solved Edit:
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
# assert false properly throws now.
assert(false)
assert(!err)
assert(result.length == 1)
assert(result[0].body)
assert(result[0].title || result[0].title2)
done()
catch e
done(e)
)
Edit2:
I've produced 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 your version does indeed work @Louis, but if you involve promises into the mix, mocha can't handle the problem, so it will hang in this example. Also try commenting out the assert false
and see it passes.
So Louis I hope I got your attention, could you explain the problem, and try catch
looks ugly indeed and I hope you find a reasonable solution to this.