문제

In stuff.js:

function init() {
    return "works";
}

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

In my test JS file:

/// <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. That is to say, an exception is thrown on the var ns2 line, and I never get to the last ok() assertion. What am I doing wrong? Shouldn't qUnit/Chutzpah have run the code in stuff.js before trying to run the test?

도움이 되었습니까?

해결책

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top