I'm working on trying to write an asynchronous test with mocha using the done(); call. This is my code so far.
it('should have data.', function () {
db.put(collection, key, json_payload)
.then(function (result) {
result.should.exist;
done();
})
.fail(function (err) {
err.should.not.exist;
done();
})
})
The result however is that the code just executes without waiting for the then or fail to actually return with a result. Does done(); need to be at a different place within the code?
Also posted the whole repo right here: https://github.com/Adron/node_testing_testing
if you want an async test you need to handle the done parameter
it('should have data.', function (done) {
db.put(collection, key, json_payload)
.then(function (result) {
result.should.exist;
done();
})
.fail(function (err) {
err.should.not.exist;
done();
})
})
also if you are using Q as your promise library you might want to complete your chain like so.
it('should have data.', function (done) {
db.put(collection, key, json_payload)
.then(function (result) {
result.should.exist;
})
.fail(function (err) {
err.should.not.exist;
})
.done(done,done)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With