【问题标题】:Chutzpah Unable to Find Reference When Running CoverageChutzpah 在运行 Coverage 时无法找到参考
【发布时间】:2018-02-16 14:47:22
【问题描述】:

我已经编写了 QUnit 测试,并在 Visual Studio 2012 中使用用于测试资源管理器的 Chutzpah 测试适配器运行它们。需要某些外部依赖项的测试,例如 jQuery 或 Kendo,在我运行代码覆盖时会失败,但在没有代码覆盖的情况下运行时不会。

为我重现问题的示例测试文件:

/// <reference path="qunit-2.5.0.js" />
/// <reference path="../Scripts/jquery-2.1.3.js" />
/// <reference path="../Components/componentEnvironment/componentEnvironment.js" />
module("repro.tests");

test("buildUrl - one part returns part", function () {
    var ce = new ComponentEnvironment();

    var output = ce.buildUrl(["http://localhost"]);

    deepEqual(output, "http://localhost");
});

test("jQuery loaded", function () {
    var fixture = $("#qunit-fixture");

    fixture.append("<div id='grandparent' class='parent grandparent'><div id='parent' class='parent child'><div id='child' class='child'></div></div></div>");

    ok(true);
});

在此示例中,当我从测试资源管理器运行它们时,两个测试都成功运行,但如果我选择分析代码覆盖率,则只有第一个测试通过(这取决于我编写的外部文件,而不是 jQuery)。

这是我的 chutzpah.json 文件:

{
    "CodeCoverageExcludes": ["jquery.*", "kendo.core.*.js"]
}

这是运行覆盖时失败测试的错误消息:

Test Name:  repro.tests jQuery loaded
Test FullName:  c:\dev\tfs\mke\web applications\internet\companydashboard\dev\companydashboard\companydashboard\tests\test.js::repro.tests::jquery loaded
Test Source:    c:\dev\tfs\mke\web applications\internet\companydashboard\dev\companydashboard\companydashboard\tests\test.js : line 14
Test Outcome:   Failed
Test Duration:  0:00:00.001

Result Message: Died on test #1 global code@file:///c:/dev/tfs/mke/web%20applications/internet/companydashboard/dev/companydashboard/companydashboard/tests/_Chutzpah.3bddafd322dddb16ba3a30cb58251b28.test.html:51:5
appendChild@[native code]: Can't find variable: $ Expected: undefined, Actual: null
Result StackTrace:  at repro.tests jQuery loaded in c:\dev\tfs\mke\web applications\internet\companydashboard\dev\companydashboard\companydashboard\tests\test.js:line 14

【问题讨论】:

    标签: javascript qunit chutzpah


    【解决方案1】:

    在您的 chutzpah.json 文件中,在列出这些依赖项(如 jquery)时的引用部分。确保设置属性“IsTestFrameworkFile:true”。这应该会有所帮助。

    【讨论】:

    • 对于引用此答案的其他人,我将其添加到我的 chutzpah.json 中: "References": [ { "Path": "../Scripts/jquery-2.1.3.js", "IsTestFrameworkFile ": "真" } ],
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    相关资源
    最近更新 更多