I am very new to AngularJS. I built an application to get a grasp on how it works and now that I have it working, I am trying to learn how to test my code. My issue with the code below is that my factory mock code fails and I am unsure of where I went wrong. Here is the error I am getting:

Controller: ProfileCtrl update test FAILED Expected spy update to have been called. Error: Expected spy Profile.show to have been called.

Controller: ProfileCtrl show test 16 FAILED Expected spy show to have been called. Error: Expected spy Profile.show to have been called.

Factory:

angular.module("profileUpdate").factory "Profile", [ "$resource" "$q" ($resource, $q) -> Profile = -> @service = $resource("/users/profiles/:id.json", {id: @id}, 'update': {method: 'PATCH', params: {id: '@id'}, headers: {'Content-Type': 'application/json'}}) return Profile::show = (userId) -> @service.get(id: userId) Profile::update = (updatedProfileObject) -> deferred = $q.defer() @service.update(id: updatedProfileObject.id, profile: updatedProfileObject).$promise.then ((data) -> deferred.resolve ("Your profile has been successfully updated!") ),(err) -> deferred.reject ("Oops...something is wrong..try again later.") return deferred.promise return new Profile ]

Controller:

angular.module("profileUpdate").controller "ProfileCtrl", [ "$scope" "$routeParams" "Profile" "$route" "$rootScope" "$timeout" ($scope,$routeParams,Profile,$route,$rootScope,$timeout) -> $rootScope.$on "$routeChangeSuccess", -> $scope.profile = Profile.show($routeParams.id) return $scope.range = (min, max, step) -> step = (if (step is `undefined`) then 1 else step) input = [] i = min while i <= max input.push i i += step input $scope.update = -> promise = Profile.update($scope.profile) promise.then((success) -> $scope.alert = success $timeout -> $scope.alert = false , 5000 ,(err) -> $scope.error = err $timeout -> $scope.error = false , 5000) ]

Test Code: