lundi 2 novembre 2015

Jasmine unit-testing on Titanium module

I am currently trying jasmine-node to unit test my Titanium app. I am open to suggestions about switching to an other unit-testing framework if it can solve my problem but first, here is my question.

My installation of jasmine-node is working, I can perform very simple tests like this one :

var util = require('../app/controllers/utils.js');
describe("util test", function(){
  it('should compute the sum between 1 & 2', function(){
      var sum = util.computeSum(1, 2);
      expect(sum).toEqual(3);
  });
});

The above code tests the following function and works as expected.

exports.computeSum = function(a,b) {
    return a+b;
};

When I try to test some code which call the Ti module though, it fails, saying "Ti is not defined".

describe("Ti.UI",function(){
    it("create custom alert", function(){
        var view = util.displayCustomAlert("title", "message");
        should(view).not.be.null;
    });
});

Above function is tested by the following test :

exports.displayCustomAlert = function(customTitle, customMessage){
    return Ti.UI.createAlertDialog({
        title:customTitle,
        message:customMessage
    });
};

How can I make jasmine-node work with Titanium ?

Aucun commentaire:

Enregistrer un commentaire