Search code examples
javascriptdojodoh

Testing Custom Modules with DOH


I'm trying to build some unit tests for an old JS file/module that is out of my control.

The JS module is built using the following pattern...

var myModule = {
    myMethod:function() {
    }
};

I am then trying to build a DOH test harness to test this. I tried the following...

require([
    "doh/runner",
    "../../myModules/myModule.js"
    ], function(doh) {
        console.log(doh);
        console.log(myModule);
    });

The file seems to be getting picked up fine but I can't reference anything in it. "console.log(myModule);" just returns undefined.

Anyone know how I can correctly include an external non dojo module JS file in a DOH test harness?

Thanks


Solution

  • You need to declare myModule in the function callback to your require statement:

    require([
        "doh/runner",
        "../../myModules/myModule"
    ], function(doh, myModule) { // <-- include myModule
        console.log(doh);
        console.log(myModule);
    });
    

    Just be sure that myModule.js returns your module.