微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 使用Chutzpah运行QUnit(TypeScript)测试,在已经启动的情况下在测试上下文之外提供“Called start()”

我有一个相当简单的复制品,结果我不明白.

确保安装了Chutpah Test Adapter 4.0.3.使用Visual Studio 2013执行以下步骤:

>创建一个新的.NET 4.5.1类库项目;
>添加NuGet包qunit.TypeScript.DefinitelyTyped 0.1.7;
>使用此内容将TypeScript文件file1.ts添加到项目中:

/// <reference path="./Scripts/typings/qunit/qunit.d.ts"/>
QUnit.test("QUnit is working",assert => assert.ok(true));

>在该文件中单击鼠标右键,然后从上下文菜单中选择“运行JS测试”.

我可以确认file1.js是按预期生成的.

结果是没有运行测试,测试资源管理器显示没有测试,测试输出显示

Error: Error: Called start() outside of a test context while already started
at start in file:///C:/Users/username/AppData/Local/Microsoft/VisualStudio/12.0/Extensions/abcxyz/TestFiles/QUnit/qunit.js (line 287)
at startQUnit in phantomjs://webpage.evaluate() (line 12)
at onPageLoaded in phantomjs://webpage.evaluate() (line 16)
in phantomjs://webpage.evaluate() (line 18)
While Running:c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts
------ Test started: File: c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts ------
Error: Error: Called start() outside of a test context while already started
While Running:c:\users\username\documents\visual studio 2013\Projects\ClassLibrary3\ClassLibrary3\file1.ts
0 passed,0 Failed,0 total (chutzpah).

========== Total Tests: 0 passed,0 total ==========

如果我选择“在浏览器中打开”Chutzpah上下文菜单项,我会得到一个常规的QUnit测试页面,格式很好,显示零测试运行.

显然,预期结果是一次测试成功运行.

在这里错过了什么?

解决方法

D’哦! The Chutzpah + TypeScript documentation实际上非常清楚:

You need to tell Chutzpah how to compile your files into JavaScript using the compile setting in the chutzpah.json file.

对于问题的场景,例如这些步骤让它工作:

>将chutzpah.json文件添加到项目的根目录.
>输入以下代码

{
    "Compile": {
        "Mode": "External","Extensions": [".ts"],"ExtensionsWithNoOutput":  [".d.ts"]
    }
}

在此之后,右键单击运行已经改善,显示

========== Total Tests: 1 passed,1 total ==========

如果这不能立即关闭并重新打开解决方案.
>要使测试显示在测试资源管理器中,您需要将它们分组到模块中,例如将其添加到file1.ts:

QUnit.module("Qu.Testing");

有关详细信息,请参阅Compile Setting documentation.

把它放在这里应该让其他人陷入我所做的同一个陷阱.

原文地址:https://www.jb51.cc/js/150495.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐