【问题标题】:Trouble running Typescript Unit Tests in Webstorm在 Webstorm 中运行 Typescript 单元测试时遇到问题
【发布时间】:2013-12-26 13:44:31
【问题描述】:

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

【问题讨论】:

    标签: unit-testing typescript


    【解决方案1】:

    import testClass = tsUnit; 行只不过是一个名称别名,即var testClass = tsUnit; 不进行任何导入。

    鉴于您正在使用手动参考 ///&lt;reference path="tsUnit.ts" /&gt; 编译使用 --out 标志并使用 reference.ts 来订购您的文件:https://github.com/basarat/grunt-ts#javascript-generation-and-ordering

    【讨论】:

    • 不会 --out 标志将所有内容编译到一个文件中吗?我不想通过将代码编译成单独的 .js 文件来保持模块化 - 每个 .ts 测试文件一个。我对客户端 JS 文件使用 RequireJS(根据您在上一个问题中提出的建议)而不是 --out 标志,所以如果我更改测试文件的设置,我对所有文件的设置都会更改,不会是吗?
    • 您能否建议一个命令行指令,仅将 tsUnit 文件的内容包含到每个单独的 tsUnit 测试文件中?
    猜你喜欢
    • 1970-01-01
    • 2018-07-24
    • 2010-11-01
    • 2016-03-21
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 2016-02-23
    相关资源
    最近更新 更多