Hi Stephen,
In unit tests you shoul init module as
beforeEach(module('consultPrototypeApp'));
The initialization that you try to use
(beforeEach(module('consultPrototypeApp',[]));) should be used just once
when you actually init module in your app (usually it's in app.js file).
But in unit tests you should just call already initialized module.
Also your expectation will not work since you did not initialized your
controller.
I will give you an example. I am sorry for possible typo since I will write
everything here:
Suppose your controller lookes something like this:
angular.module('consultPrototypeApp').controller('AppCtrl',
function($scope){
$scope.sayHello = function {
$scope.text = "Hello World";
}
})
You could unit test it as following:
describe('App controller', function(){
// since controller uses scope as dependency we should init it as well
var scope, controller;
beforeEach(module('consultPrototypeApp'));
beforeEach(inject(function(_$rootScope_, _$controller_{
scope = _$rootScope_.$new();
// using $controller service to properly init controller
controller = _$controller_('AppCtrl', {$scope:scope});
// and unit test would be like this
it('should be able to sayHello', function(){
scope.sayHello();
expect(scope.text).toEqual('Hello World');
});
}));
});
I hope it will help.
Cheers,
Vitaly
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.