I'm having a hard time to get my head around Jasmine. The following test is failing with the message "Expected spy init to have been called. at Object.."
The Test
beforeEach(module('myModule'));
it('Should execute myCtrl.init() on controller instantiation', function () {
var $scope = $rootScope.$new();
$scope.foo = 'bar';
var MyCtrl = $controller('MyCtrl', {
$scope: $scope
});
spyOn($scope, 'init');
expect($scope.init).toHaveBeenCalled();
expect($scope.foo).toBe('bar');
});
The Controller
angular.module('myModule')
.controller('MyCtrl', [
'$scope'
function($scope) {
$scope.init = $scope.init || function init () {
$scope.foo = $scope.foo || 'baz';
};
$scope.init();
}]);
What am I missing?
$scope.init = $scope.init || function init () { $scope.foo = $scope.foo || 'baz'; };?