In 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:
/// <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. What am I doing wrong? Shouldn't qUnit/Chutzpah have run the code in stuff.js before trying to run the test?
I missed this the first time around. Setting anything to the empty object works, but that reference still evaluates to 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.