麻烦在Webstorm中运行Typescript单元测试

时间:2013-12-26 13:44:31

标签: unit-testing typescript

我正在尝试使用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

1 个答案:

答案 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