0

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 ?

midemarc
  • 113
  • 1
  • 1
  • 12
  • Hey did you ever got this figured out? – user1554966 Nov 02 '17 at 15:28
  • @user1554966 I don't recall I have. I was an intern at that time, without much time in my hands ; I think I just went on without testing Titanium components. It was probably for the best though, you should really trust that the framework does its job and only test your custom code. – midemarc Nov 03 '17 at 16:57

1 Answers1

0

I'd recommend using TiShadow to run Jasmine tests or TiO2 to run Mocha tests for Titanium apps.

Fokke Zandbergen
  • 3,866
  • 1
  • 11
  • 28
  • I tried tio2 before jasmine, but I haven't been able to make it work. The simple `example` sample fails with errors without pointing at them, and I encounter [this issue](https://github.com/appcelerator/tio2/issues/14) by running on my project. I find the `read me` does not provide enough informations to make in work. I will give TiShadow a try, thank you. – midemarc Nov 03 '15 at 08:32