0

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.

streetlight
  • 5,968
  • 13
  • 62
  • 101

1 Answers1

0

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)

hereandnow78
  • 14,094
  • 8
  • 42
  • 48
  • How would i go about mocking the browser variables? The second is an option I'm leaning towards but trying to avoid – streetlight Jan 29 '14 at 14:48
  • I think you would have to mock the entire DOM. You could try jsdom (https://github.com/tmpvar/jsdom). However, I'd run with latter option as you probably want to test in different browsers. It is better to separate the application logic from DOM manipulation in your code then you can easily test the logic without the need to mock-up a browser/DOM. The DOM manipulation parts of your code can then be tested in a separate set of tests. This is of course an idealist approach and not possible much of time; to the extent that it can be achieved it worth aiming for. – Stephen Simpson Jan 29 '14 at 16:08