mardi 24 mai 2016

Mocha/Should.js using asynchronous function

I'm new to JavaScript test frameworks. I would like to do a little optimization but I run into some problems. The project is using should.js

Here is the simplified version of my original test cases:

describe('Simple', function() {
  describe('Test', function() {
    it('should do something', function(done) {
      somePromise.then(function(data) {
        data.should.above(100);
        done();
      });
    }

    it('should do something else but alike', function(done) {
      somePromise.then(function(data) {
        data.should.above(100);
        done();
      });
    }

  }
});

I'm trying to do it this way:

var testFunc = function(data) {
  it('should do something', function(done) {
      data.should.above(100);
      done();
  });
}

describe('Simple', function() {
  describe('Test', function() {
      somePromise.then(function(data) {
        testFunc(data);
      });

      somePromise.then(function(data) {
        testFunc(data);
      });
  }
});

The promise is asynchronous, and maybe that's the reason why my "optimization" didn't work? I've found no "done" callback for describe function in docs.

Thanks in advance! Any help will be appreciate!

Aucun commentaire:

Enregistrer un commentaire