[英]Testing javascript closure in jasmine
我對使用茉莉花完全陌生。 我不知道如何為如下所示的JavaScript關閉編寫測試用例。
我在Typescript中的代碼如下:
module FIRST.Mobile.Controllers{
"use strict";
class sampletest
{
public subtract(a: number, b: number): number {
return a - b;
}
}
}
當轉換為JavaScript時,它變為:
var FIRST;
(function (FIRST) {
var Mobile;
(function (Mobile) {
var Controllers;
(function (Controllers) {
"use strict";
var sampletest = (function () {
function sampletest() {
}
sampletest.prototype.subtract = function (a, b) {
return a - b;
};
return sampletest;
})();
})(Controllers = Mobile.Controllers || (Mobile.Controllers = {}));
})(Mobile = FIRST.Mobile || (FIRST.Mobile = {}));
})(FIRST || (FIRST = {}));
我不知道我是否可以在打字稿模塊中測試代碼? 如果可以,有人可以解釋一下如何使用茉莉花測試減法。
您實際提供的代碼與閉包無關。
您可以通過以下方式訪問類sampletest
(我建議在CamelCase中將其編寫為SampleTest
): FIRST.Mobile.Controllers.sampletest
您的函數subtract()
在這里:
var t = new FIRST.Mobile.Controllers.sampletest();
t.subtract(5, 3); // returns 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.