Running DOH tests through node -- 'document is not defined'

701 views Asked by At

I'm trying to get my DOH tests working via the command line for easy testing. However, I'm running into some issues and need some direction!

I am currently running the following test module:

define([
    "doh/runner",
    "dojo/query"
 ], function (
    doh,
    query
) {
    doh.register("Homepage Tests", [{
        name: "Sanity Check",
        runTest: function () {
            return doh.assertNotEqual("Cat", "Dog");
        }
    }]);
});

It works in the browser fine. However, when I run the following command:

node path/to/dojo.js load=doh path/to/test/module.js

I get the following error (abbreviated somewhat):

 /public/bower_components/dojo/selector/_loader.js:5
  var testDiv = document.createElement("div");
          ^
  ReferenceError: document is not defined
  at /public/bower_components/dojo/selector/_loader.js:5:15

Is this because the test isn't spun in up in a phantomJS browser, so it doesn't have access to browser variables? Is there a way to make dojo doh tests that work in the browser work here easily?

For clarity, I am using the grunt-doh plugin (https://github.com/gpbl/grunt-doh) which runs the above command.

1

There are 1 answers

2
hereandnow78 On BEST ANSWER

this will not work, exactly because of this:

Is this because the test isn't spun in up in a phantomJS browser, so it doesn't have access to browser variables? Is there a way to make dojo doh tests that work in the browser work here easily?

i dont know much about DOH, and what is possible with it, but you need to

a) mock document

or

b) write your own grunt-task which spawns a connect-server with grunt-contrib-connect and runs your tests inside that browser

EDIT: for mocking in DOH see this link (search for Mocking methods)