当要测试的类在模块定义中时,我无法弄清楚如何在TypeScript中编写Jasmine测试。此设置工作正常:
Calculator.ts:
export class Calculator {
add(x: number, y: number): number {
return x + y;
}
}
CalculatorTest.ts:
///<reference path="scripts/typings/jasmine/jasmine.d.ts"/>
///<reference path="../NancyApplication506/app/Calculator.ts"/>
import Calculator = require("../NancyApplication506/app/Calculator");
describe("Calculator tests", () => {
var calculator: Calculator.Calculator;
beforeEach(() => {
calculator = new Calculator.Calculator();
});
it("should be able to add", () => {
expect(calculator.add(21,21)).toBe(42);
});
});
但是当我改变这样的计算器时,我一直无法弄清楚如何编写我的测试。
module SomeModuleName {
export class Calculator {
add(x: number, y: number): number {
return x + y;
}
}
}
我尝试过几十种不同的东西,都导致完全失败。请帮忙!
答案 0 :(得分:0)
将Chutzpah.json文件添加到与测试相同的目录中:
{
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ],
"SourceDirectory": "../",
"OutDirectory": "../"
}
}
然后删除:
import Calculator = require("../NancyApplication506/app/Calculator");