Closed tgvashworth closed 11 years ago
what's the compiled code? maybe CS is fucking it up
Could it be the returns?
return it('should be able to grab things from Typekit', function(done) {
return $.getJSON('http://typekit.com/api/v1/json/kits/qba6sms/published?callback=?', function(data, txt, xhr) {
data.should.be.ok;
return done();
});
});
they shouldn't matter
Didn't think so, any other ideas? Mocha's compiling it on the fly... I might try compiling it with coffee and running the tests on that code.
Just tried chai – expect(data)
works great, but should
times out.
describe 'typekit', () ->
it 'should be able to fetch the example kit', (done) ->
this.timeout 8 * 1000
typekit.get 'http://typekit.com/api/v1/json/kits/qba6sms/published?callback=?', (data) ->
data.kit.id.should.equal 'qba6sms'
done()
it 'should be able to fetch my kits', (done) ->
this.timeout 8 * 1000
typekit.get 'http://typekit.com/api/v1/json/kits?token=xxxxx&callback=?', (data) ->
data.should.be.a 'object'
done()
Top works, bottom times out. When I add data.should.be.a 'object'
to the top, it times out. This ain't the CS – exact same problem with raw JS tests.
some browsers don't really properly expose uncaught exceptions that's probably why it's timing out
I'm using Mocha in watch mode (although it fails in normal mode too):
@./node_modules/.bin/mocha -w -R min -r should --compilers coffee:coffee-script
oh i see this is with node, i'll look into it soon
Thanks.
Some more info, for that last bit of code:
First example: typeof data.kit.id.should
is object
Second example: typeof data.should
is undefined
In both cases data
is an object
.
Having the exact same problem. Tests timeout with should. Using the latest versions of node, mocha and should.
I have now tested it with chai and without should and experienced the same problem... So it seems to be more related to mocha than should.
Having the same issue, where a failed should
assertion causes mocha test to time out and never call done. This happens within a return mongoose promise.
Show me your code.
model
schema.statics.ignite = function (foo) {
var prom = new mongoose.Promise();
setTimeout(function () {
prom.resolve(null, 'foobar');
} , 500);
return prom;
};
test
it('failing test in resolved promise times out', function (done) {
Model.ignite('foo')
.then(function (flare) {
true.should.be.false;
done();
}, done);
});
Not sure about mongosee promises, but q.js require to add to final promise .done() or return it. Maybe the same with mongoose promises? In should there is nothing to block.
Ahh, thanks @btd , I needed to add the #end
to finalized the chain. But there is not chain ;) I thought you only needed to call end
if you were chaining then
's.
it('failing test in resolved promise times out', function (done) {
Model.ignite('foo')
.then(function (flare) {
true.should.be.false;
done();
}, done)
.end();
});
+1
The thing you are encountering is nothing to do with mocha
, should
or even chai
. It caused by promise.
When the should
fails, Promise
turn the process into reject
state, instead throw the error directly.
Just modify your code as following:
it('promise', function(done) {
new Promise(function(resolve, inject){
setTimeout(function(){
resolve(false);
}, 20);
})
.then(function(state) {
state.should.be.ok;
done();
})
.catch(done);
});
You have to catch
the error yourself
I'm running Mocha in watch mode, compiling CoffeeScript tests.
I'm not sure what's up – am I doing something wrong, or is it a bug?