I'm having some trouble adapting this test to use the "controller as" syntax. Here's what I have ...
The controller I'm testing is:
function MyCtrl ($scope, someService) {
someService.get()
.success(function(data){
$scope.person = data;
});
}
angular.module('myApp')
.controller('MyCtrl', MyCtrl);
The unit test is:
beforeEach(module('myApp'));
var scope,
fakeService,
controller,
q,
deferred;
beforeEach(function () {
fakeService = {
get: function () {
deferred = q.defer();
deferred.resolve({ "test": "data" });
return deferred.promise;
}
};
spyOn(fakeService, 'get').and.callThrough();
});
beforeEach(inject(function ($controller, $q, $rootScope) {
q = $q;
scope = $rootScope.$new();
controller = $controller('MyCtrl as person', { $scope: scope, someService: fakeService });
}));
it('The person object is not defined yet', function () {
expect(scope.person).not.toBeDefined();
});
This test for scope.person
fails with the error TypeError: undefined is not a function
.
I've tried this solution where I've changed expect(scope.person)
to expect(scope)
, but that returns TypeError: undefined is not a function
.
I'm using AngularJS 1.2.22, Karma 0.12.21 and 0.2.2 of the karma-jamsine plugin.
Thanks in advance for whatever suggestions you have.