0

在 stuff.js 中:

function init() {
    return "works";
}

(function(ParentNamespace) {
    ParentNamespace.MySubNamespace = {};
})(window.MyNamespace || (window.MyNamespace = {}));

在我的测试 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");
});

'undefined' is not an object (evaluating 'window.MyNamespace.MySubNamespace')在使用 Chutzpah 测试适配器运行上述测试时得到。也就是上var ns2线抛出异常,一直到最后一个ok()断言都没有。我究竟做错了什么?qUnit/Chutzpah 不应该在尝试运行测试之前运行 stuff.js 中的代码吗?

4

1 回答 1

1

我已经改变了测试。以下测试工作...

/// <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");
});
于 2013-01-30T06:44:05.880 回答