我有一个相当简单的重现,结果我不明白。
确保安装了 Chutpah 测试适配器 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 failed, 0 total ==========
如果我选择“在浏览器中打开”Chutzpah 上下文菜单项,我会得到一个常规的 QUnit 测试页面,格式很好,显示零测试运行。
显然预期的结果是成功运行了一个测试。
我在这里错过了什么?
最佳答案
噢! 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, 0 failed, 1 total ==========
如果不能立即关闭并重新打开解决方案。
要让测试显示在测试资源管理器中,您需要将它们分组到模块中,例如通过将此添加到
file1.ts
:QUnit.module("Qu.Testing");
有关详细信息,请参阅 Compile Setting documentation .
如果其他人落入我所做的相同陷阱,请将其留在此处。
关于javascript - 使用 Chutzpah 运行 QUnit (TypeScript) 测试给出 "Called start() outside of a test context while already started",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31540707/