简体   繁体   English

qUnit是否没有像浏览器那样运行安装代码?

[英]qUnit isn't running setup code like a browser would?

In stuff.js: 在stuff.js中:

function init() {
    return "works";  // just here to ensure we can access this file from the test
}

window.MyNamespace = {};

In my test JS file: 在我的测试JS文件中:

/// <reference path="../../../project1/Shared/sub1/Javascript/stuff.js" />
test("foo test", function () {
    equal(init(), "works", "couldn't access source JS file");
    ok(window, "couldn't access source JS file");
    var ns = window.MyNamespace;
    ok(ns, "namespace is bad");
});

I get namespace is bad when running the above test using Chutzpah Test Adapter. 使用Chutzpah测试适配器运行上述测试时,我得到的namespace is bad What am I doing wrong? 我究竟做错了什么? Shouldn't qUnit/Chutzpah have run the code in stuff.js before trying to run the test? 在尝试运行测试之前,qUnit / Chutzpah是否应该已经在stuff.js中运行了代码?

I missed this the first time around. 我第一次错过了这个。 Setting anything to the empty object works, but that reference still evaluates to false. 将任何内容设置为空对象都可以,但是该引用仍然评估为false。 That is why the ok assertion fails. 这就是为什么确定断言失败的原因。 I needed to do a more proper check for strictly undefined: 我需要对严格未定义的内容进行更适当的检查:

ok("ns" in window, "namespace is bad");

per the top answer here . 按照这里的最高答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM