我正在尝试使用tsUnit运行Typescript的单元测试。我已经包含了tsUnit路径。我导入它的方式似乎有问题。
///<reference path="tsUnit.ts" />
import testClass = tsUnit;
class IDTest extends tsUnit.TestClass {
selectIDTest() {
...
this.areIdentical("#" + id, idSelector);
}
setAsRootTest() {
...
this.areIdentical("root", target.setAsRoot());
}
}
var test = new tsUnit.Test();
test.addTestClass(new IDTest());
test.showResults(document.getElementById('results'), test.run());
这是错误:
Uncaught ReferenceError: tsUnit is not defined IDTest.ts:8:21
(anonymous function) IDTest.ts:8:21
Uncaught SyntaxError: Unexpected token : chrome-extension://mgjjeipcdnnjhgodgjpfkffcejoljijf/shortcut_manager.js
(anonymous function) chrome-extension://mgjjeipcdnnjhgodgjpfkffcejoljijf/shortcut_manager.js
(anonymous function) extensions::messaging
target.(anonymous function) extensions::SafeBuiltins
Event.dispatchToListener extensions::event_bindings
Event.dispatch_ extensions::event_bindings
Event.dispatch extensions::event_bindings
dispatchOnMessage extensions::messaging
答案 0 :(得分:0)
行import testClass = tsUnit;
只不过是名称别名,即var testClass = tsUnit;
不进行任何导入。
鉴于您使用手动参考///<reference path="tsUnit.ts" />
使用--out
标记进行编译,并使用reference.ts订购文件:https://github.com/basarat/grunt-ts#javascript-generation-and-ordering