我对使用茉莉花完全是个新手。我不知道如何为下面这样的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 = {}));我不明白是否可以在typescript模块中测试代码?如果是,有人能告诉我如何使用jasmine测试subtract方法吗?
发布于 2016-06-14 14:31:33
您提供的代码实际上与闭包无关。
您可以通过以下方式访问sampletest类(我建议在CamelCase中将其编写为SampleTest):FIRST.Mobile.Controllers.sampletest
你的函数subtract()在这里:
var t = new FIRST.Mobile.Controllers.sampletest();
t.subtract(5, 3); // returns 2https://stackoverflow.com/questions/37800706
复制相似问题