I have a simple test in controllersSpec.coffee Angular App code:
describe 'Controllers', ->
beforeEach ->
angular.module 'app'
describe 'MainCtrl', ->
beforeEach inject ($controller, $rootScope) ->
scope = $rootScope.$new()
ctrl = $controller 'MainCtrl', $scope: scope
it 'should be true', ->
expect(true).toEqual(true)
And SpecRunner.html file for testing:
<html lang="eu">
<head>
<title>Angular Test Runner</title>
<script src="../js/libs/jquery.js"></script>
<script src="lib/jasmine.js"></script>
<script src="lib/jasmine-html.js"></script>
<script src="../js/libs/underscore.js"></script>
<script src="../js/libs/angular.js"></script>
<script src="lib/angular/angular-mocks.js"></script>
<script src="lib/angular/angular-scenario.js" ng-autotest></script>
<script src="../js/controllers.js"></script>
<script src="controllersSpec.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>
That throw error, about '$modules' in angular-mock:
TypeError: Cannot read property '$modules' of null
at Object.workFn (http://localhost/lolobot/test/lib/angular/angular-mocks.js:1745:25)
at Object.<anonymous> (http://localhost/lolobot/test/lib/angular/angular-scenario.js:24673:54)
at Array.forEach (native)
at Object.forEach (http://localhost/lolobot/test/lib/angular/angular-scenario.js:9538:11)
Can u help me with that problem? It's my first test angular app.
I think you need some more Angular packages included. I'm including the whole suite in my runner. I don't imagine I actually need them all, but I've tried to remove a few and had failures. Specifically, I have exactly these:
angular.js
angular-bootstrap.js
angular-cookies.js
angular-loader.js
angular-mocks.js
angular-resource.js
angular-sanitize.js
Also, in your tests, you probably want to have
controller = null
scope = null
before anything else in your describe block. Otherwise your controller and scope end up as local variables in your inject function.