lundi 25 janvier 2016

Angular is not defined Error while testing with Mocha, Chai, Sinonjs

My problem lies here where I am trying to test a controller within angular. This is the error the console throws to me when running the command mocha --compilers coffee:coffee-script/register **/*.spec.coffee to run all testing files within the project.

  angular.module('weaver.ui.app');
  ^
ReferenceError: angular is not defined

I recently added angular-mocks library which makes sure angular is not an unresolved variable, but this doesn't resolve the problem.

My beginning of my testing file looks like this (the code is written is CoffeeScript)

# angular = require 'angular'
angular.module 'weaver.ui.app'

chai = require 'chai'
sinon = require 'sinon'

If I uncomment the require angular the error changes into the following, so I assume this is not the right way.

\npm\node_modules\angular\angular.js:29016
})(window, document);
   ^

ReferenceError: window is not defined

And if I remove the line angular.module 'weaver.ui.app' completely I get a similar error but this one is about the controller.

  angular.module('weaver.ui.app').controller('AppDesignSidebarNewcontentCtrl', function($rootScope, $scope) {});
  ^

ReferenceError: angular is not defined

I hope someeone here can help me with this problem which is bugging me for quite a while now.

Please do not judge me on the name of the controller ;)

Aucun commentaire:

Enregistrer un commentaire