'use strict'
webApp.controller 'NavigationController', [
'$scope'
'$rootScope'
'UserService'
($scope, $rootScope, UserService) ->
$scope.init = ->
UserService.isAuthenticated().then (authenticated) ->
$scope.isAuthenticated = authenticated
$scope.init()
]
我想写一个测试spyOn
ifisAuthenticated
被调用 from UserService
。在我的beforeEach
,我有:
beforeEach ->
module 'webApp'
inject ($injector) ->
$httpBackend = $injector.get '$httpBackend'
$q = $injector.get '$q'
$rootScope = $injector.get '$rootScope'
$scope = $rootScope.$new()
$controller = $injector.get '$controller'
UserServiceMock =
isAuthenticated: ->
deferred = $q.defer()
deferred.promise
controller = $controller 'AboutUsController',
'$scope': $scope
'$rootScope': $rootScope
'UserService': UserServiceMock
$httpBackend.whenGET('/api/v1/session').respond 200
任何帮助将不胜感激..谢谢