mardi 1 décembre 2015

Jasmine - Running beforeAll blocks in series

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.

  1. Reset the database
  2. Create a lecture in the database
  3. Create a question in the database
  4. Go to the page of the just created lecture
  5. 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

Aucun commentaire:

Enregistrer un commentaire