I'm trying to test if some of my db operations are executed properly. The flow is as follows (I'm using mocha for testing)
I'm noticing that the get data from db gets executed much before anything is saved. I was looking at the done() option in mocha, however that seems to work only if data is saved through mocha (setup etc).
So how do I instruct mocha to wait for all db to be saved before trying to retrieve from db?
Thanks for any help
dankohn is correct. Here's what you need to do, a bit more fleshed out:
describe('Your test', function () {
before(function (done) {
Your.redis.db.call.here(your, parameters, function (err) {
...you may want to check for errors first...
done();
});
});
it('should do what you wanted...', function (done) {
...your test case...
done();
});
});
Your redis call most likely provides a callback function as a parameter. That callback function is executed when the redis call is completed. Within that callback function, call done(). The data you wrote will be there throughout your tests.
You just need to write a before function with the parameter done in mocha to load the data into the database. As a callback for when your data is loaded, call done(). Now, all your data will load before your first test.