I am trying to write a unit test for an AngularJS directive (which is wrapped in an module for requiring via requirejs), loading modules with requirejs, but I'm having issues with the global window object when loading in angular.
My current understanding is that I need to instantiate an angular app, add my directive to it, and then get the angular compiler to run on some HTML which contains the directive name. From that point on, I can test as usual.
However, when try to require angular in my test, I get the following error:
Uncaught Error: Evaluating c:\...\angular.js as module "angular" failed with error: ReferenceError: window is not defined
Some people suggested installing jsdom in order to get a window object, but from the error message above, you might be able to work out that I'm in a Windows environment and that combination seems to be painful.
At the moment, my test is simple:
// Imports, including requirejs config
describe("Directive tests", function() {
var angular;
before(function(done) {
requirejs(['angular'], function(a) {
angular = a;
});
});
});
I could go down the route of defining a window module in requirejs and have a mock version injected in the tests, but that seems like a lot of work.