[英]QUnit isn't running manually namespaced setup code like I would expect?
In stuff.js: 在stuff.js中:
function init() {
return "works";
}
(function(ParentNamespace) {
ParentNamespace.MySubNamespace = {};
})(window.MyNamespace || (window.MyNamespace = {}));
In my test JS file: 在我的测试JS文件中:
/// <reference path="../../../project1/Shared/sub1/Javascript/stuff.js" />
test("foo test", function () {
deepEqual(init(), "works", "couldn't access source JS file");
ok(window, "no window context");
var ns = window.MyNamespace;
ok(ns in window, "namespace is bad");
var ns2 = window.MyNamespace.MySubNamespace;
ok(ns2 in window, "subnamespace is bad");
});
I get 'undefined' is not an object (evaluating 'window.MyNamespace.MySubNamespace')
when running the above test using Chutzpah Test Adapter. 使用Chutzpah测试适配器运行上述测试时,我得到
'undefined' is not an object (evaluating 'window.MyNamespace.MySubNamespace')
。 That is to say, an exception is thrown on the var ns2
line, and I never get to the last ok()
assertion. 也就是说,在
var ns2
行上引发了一个异常,而我从没有到最后的ok()
断言。 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 have changed the test. 我改变了测试。 Following test works...
后续测试工作...
/// <reference path="../../../project1/Shared/sub1/Javascript/stuff.js" />
test("foo test", function () {
deepEqual(init(), "works", "couldn't access source JS file");
ok(window, "no window context");
ok('MyNamespace' in window, "namespace is bad");
ok('MySubNamespace' in window.MyNamespace, "subnamespace is bad");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.