Before testing a certain feature of my Meteor application with Jasmine I have to prepare different things for the tests. Therefore I use beforeAll blocks.
- Reset the database
- Create a lecture in the database
- Create a question in the database
- Go to the page of the just created lecture
- Wait for the Router to finish routing
These asynchronous tasks have to run in series. I can not first go to the lecture page and then create it in the database. Sadly beforeAll blocks in Jasmine will not automatically run in series.
This is my current code:
beforeAll(function(done) {
Fixtures.clearDB(done);
});
beforeAll(function(done) {
Fixtures.createLecture({}, function(error, result) {
lectureCode = result;
done();
});
});
beforeAll(function(done) {
Fixtures.createQuestion({}, done);
});
beforeAll(function(done) {
Router.go('lecturePage', {lectureCode: lectureCode});
Tracker.afterFlush(done);
});
beforeAll(waitForRouter);
it("....", function() {
...
});
How can I write this code in Jasmine in a pretty style without going into callback hell?
The Source Code of the entire application is open source and can be found on GitHub
Thank you very much in advance, Max
Here you are:
I haven't tested it but I hope you get an idea. You need to create list of functions, each of them will be provided with callback function that you need to call to make next function run. After that final callback is called where we can call done() to tell jasmine that we're done. Hope this helps.