我目前正在嘗試茉莉節點來單元測試我的鈦應用程序。如果能夠解決我的問題,我很樂意提供有關切換到其他單元測試框架的建議,但首先,這是我的問題。茉莉花單元測試鈦模塊
我的茉莉花節點的安裝工作,我可以進行非常簡單的測試,像這樣的:
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);
});
});
上面的代碼測試以下功能和按預期工作。
exports.computeSum = function(a,b) {
return a+b;
};
當我嘗試測試一些調用Ti模塊的代碼時,它失敗,說「Ti未定義」。
describe("Ti.UI",function(){
it("create custom alert", function(){
var view = util.displayCustomAlert("title", "message");
should(view).not.be.null;
});
});
以上功能是通過以下測試進行測試:
exports.displayCustomAlert = function(customTitle, customMessage){
return Ti.UI.createAlertDialog({
title:customTitle,
message:customMessage
});
};
我怎樣才能讓用鈦茉莉節點的工作?
嘿,你有沒有想過這個? – user1554966
@ user1554966我不記得我有。當時我是一名實習生,沒有多少時間在我的手中;我想我沒有測試鈦部件。 雖然這可能是最好的,但您應該確信該框架可以完成其工作,並且只能測試您的自定義代碼。 – midemarc